From 9e920f12c9397ec7f61ecc5559b87d1ff8b9ad38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Calder=C3=B3n?= Date: Thu, 21 Feb 2019 11:25:42 -0300 Subject: [PATCH] Add password length validation on create CLI In this commit we add this validation importing the walletunlocker.ValidatePassword function on create wallet command. --- cmd/lncli/commands.go | 10 +++++++++- walletunlocker/service.go | 8 ++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index 419ecb45..b9e04c6d 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -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" @@ -265,7 +266,7 @@ var listUnspentCommand = cli.Command{ confirmations. Use --min_confs=0 to include unconfirmed coins. To list all coins with at least min_confs confirmations, omit the second argument or flag '--max_confs'. To list all confirmed and unconfirmed - coins, no arguments are required. To see only unconfirmed coins, use + coins, no arguments are required. To see only unconfirmed coins, use '--unconfirmed_only' with '--min_confs' and '--max_confs' set to zero or not present. `, @@ -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 ( diff --git a/walletunlocker/service.go b/walletunlocker/service.go index 5efc211b..747a9e54 100644 --- a/walletunlocker/service.go +++ b/walletunlocker/service.go @@ -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")