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:
commit
3371c5fab0
@ -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"
|
||||||
@ -265,7 +266,7 @@ var listUnspentCommand = cli.Command{
|
|||||||
confirmations. Use --min_confs=0 to include unconfirmed coins. To list
|
confirmations. Use --min_confs=0 to include unconfirmed coins. To list
|
||||||
all coins with at least min_confs confirmations, omit the second
|
all coins with at least min_confs confirmations, omit the second
|
||||||
argument or flag '--max_confs'. To list all confirmed and unconfirmed
|
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
|
'--unconfirmed_only' with '--min_confs' and '--max_confs' set to zero or
|
||||||
not present.
|
not present.
|
||||||
`,
|
`,
|
||||||
@ -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")
|
||||||
|
Loading…
Reference in New Issue
Block a user