Add password length validation on create CLI

In this commit we add this validation importing
the walletunlocker.ValidatePassword function on
create wallet command.
This commit is contained in:
Francisco Calderón 2019-02-21 11:25:42 -03:00
parent 4de9ffdf7b
commit 9e920f12c9
No known key found for this signature in database
GPG Key ID: 8D4BACBFA6023C29
2 changed files with 13 additions and 5 deletions

@ -20,6 +20,7 @@ import (
"github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/walletunlocker"
"github.com/urfave/cli" "github.com/urfave/cli"
"golang.org/x/crypto/ssh/terminal" "golang.org/x/crypto/ssh/terminal"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -1334,6 +1335,13 @@ func create(ctx *cli.Context) error {
return fmt.Errorf("passwords don't match") 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 // Next, we'll see if the user has 24-word mnemonic they want to use to
// derive a seed within the wallet. // derive a seed within the wallet.
var ( var (

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