Fix Change Wallet Password Logic (#7324)

* fix change password logic
* gaz
* Merge refs/heads/master into change-password-fix
* Merge refs/heads/master into change-password-fix
* Merge refs/heads/master into change-password-fix
* Merge refs/heads/master into change-password-fix
* Merge refs/heads/master into change-password-fix
* Merge refs/heads/master into change-password-fix
* Merge refs/heads/master into change-password-fix
* Merge refs/heads/master into change-password-fix
* Merge refs/heads/master into change-password-fix
* Merge refs/heads/master into change-password-fix
This commit is contained in:
Raul Jordan
2020-09-24 11:47:13 -05:00
committed by GitHub
parent 1bc0cc7049
commit 76a3070fd7
4 changed files with 12 additions and 45 deletions

View File

@@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
"github.com/dgrijalva/jwt-go"
@@ -67,7 +68,10 @@ func (s *Server) Login(ctx context.Context, req *pb.AuthRequest) (*pb.AuthRespon
WalletDir: defaultWalletPath,
WalletPassword: req.Password,
}); err != nil {
return nil, status.Error(codes.Internal, "Could not initialize wallet")
if strings.Contains(err.Error(), "invalid checksum") {
return nil, status.Error(codes.Unauthenticated, "Incorrect password")
}
return nil, status.Errorf(codes.Internal, "Could not initialize wallet: %v", err)
}
return s.sendAuthResponse()
}

View File

@@ -165,6 +165,9 @@ func (s *Server) ChangePassword(ctx context.Context, req *pb.ChangePasswordReque
return nil, status.Error(codes.FailedPrecondition, "Not a valid direct keymanager")
}
s.wallet.SetPassword(req.Password)
if err := s.wallet.SaveHashedPassword(ctx); err != nil {
return nil, status.Errorf(codes.Internal, "Could not save hashed password: %v", err)
}
if err := km.RefreshWalletPassword(ctx); err != nil {
return nil, status.Errorf(codes.Internal, "Could not refresh wallet password: %v", err)
}
@@ -174,6 +177,9 @@ func (s *Server) ChangePassword(ctx context.Context, req *pb.ChangePasswordReque
return nil, status.Error(codes.FailedPrecondition, "Not a valid derived keymanager")
}
s.wallet.SetPassword(req.Password)
if err := s.wallet.SaveHashedPassword(ctx); err != nil {
return nil, status.Errorf(codes.Internal, "Could not save hashed password: %v", err)
}
if err := km.RefreshWalletPassword(ctx); err != nil {
return nil, status.Errorf(codes.Internal, "Could not refresh wallet password: %v", err)
}