cmd/lncli: add changepassword command

This commit is contained in:
Wilmer Paulino 2018-04-20 03:14:51 -04:00
parent 58a3419283
commit 4e2ae89219
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
2 changed files with 67 additions and 6 deletions

@ -1382,6 +1382,66 @@ func unlock(ctx *cli.Context) error {
return nil return nil
} }
var changePasswordCommand = cli.Command{
Name: "changepassword",
Category: "Startup",
Usage: "Change an encrypted wallet's password at startup.",
Description: `
The changepassword command is used to Change lnd's encrypted wallet's
password. It will automatically unlock the daemon if the password change
is successful.
If one did not specify a password for their wallet (running lnd with
--noencryptwallet), one must restart their daemon without
--noencryptwallet and use this command. The "current password" field
should be left empty.
`,
Action: actionDecorator(changePassword),
}
func changePassword(ctx *cli.Context) error {
ctxb := context.Background()
client, cleanUp := getWalletUnlockerClient(ctx)
defer cleanUp()
fmt.Printf("Input current wallet password: ")
currentPw, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
return err
}
fmt.Println()
fmt.Printf("Input new wallet password: ")
newPw, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
return err
}
fmt.Println()
fmt.Printf("Confirm new wallet password: ")
confirmPw, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
return err
}
fmt.Println()
if !bytes.Equal(newPw, confirmPw) {
return fmt.Errorf("passwords don't match")
}
req := &lnrpc.ChangePasswordRequest{
CurrentPassword: currentPw,
NewPassword: newPw,
}
_, err = client.ChangePassword(ctxb, req)
if err != nil {
return err
}
return nil
}
var walletBalanceCommand = cli.Command{ var walletBalanceCommand = cli.Command{
Name: "walletbalance", Name: "walletbalance",
Category: "Wallet", Category: "Wallet",

@ -194,6 +194,7 @@ func main() {
app.Commands = []cli.Command{ app.Commands = []cli.Command{
createCommand, createCommand,
unlockCommand, unlockCommand,
changePasswordCommand,
newAddressCommand, newAddressCommand,
sendManyCommand, sendManyCommand,
sendCoinsCommand, sendCoinsCommand,