Merge pull request #2680 from grunch/passwd-length-validation-on-create-wallet

Add password length validation condition on create wallet cli
This commit is contained in:
Wilmer Paulino 2019-03-12 12:12:54 -07:00 committed by GitHub
commit 3371c5fab0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

@ -20,6 +20,7 @@ import (
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/walletunlocker"
"github.com/urfave/cli"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/net/context"
@ -1334,6 +1335,13 @@ func create(ctx *cli.Context) error {
return fmt.Errorf("passwords don't match")
}
// If the password length is less than 8 characters, then we'll
// return an error.
pwErr := walletunlocker.ValidatePassword(pw1)
if pwErr != nil {
return pwErr
}
// Next, we'll see if the user has 24-word mnemonic they want to use to
// derive a seed within the wallet.
var (

@ -184,7 +184,7 @@ func (u *UnlockerService) InitWallet(ctx context.Context,
// Make sure the password meets our constraints.
password := in.WalletPassword
if err := validatePassword(password); err != nil {
if err := ValidatePassword(password); err != nil {
return nil, err
}
@ -316,7 +316,7 @@ func (u *UnlockerService) ChangePassword(ctx context.Context,
}
// Make sure the new password meets our constraints.
if err := validatePassword(in.NewPassword); err != nil {
if err := ValidatePassword(in.NewPassword); err != nil {
return nil, err
}
@ -358,8 +358,8 @@ func (u *UnlockerService) ChangePassword(ctx context.Context,
return &lnrpc.ChangePasswordResponse{}, nil
}
// validatePassword assures the password meets all of our constraints.
func validatePassword(password []byte) error {
// ValidatePassword assures the password meets all of our constraints.
func ValidatePassword(password []byte) error {
// Passwords should have a length of at least 8 characters.
if len(password) < 8 {
return errors.New("password must have at least 8 characters")