lncli: use readPassword function everywhere
This commit is contained in:
parent
070cfb804f
commit
d792a8ef61
@ -14,7 +14,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
@ -26,7 +25,6 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
"github.com/lightningnetwork/lnd/walletunlocker"
|
"github.com/lightningnetwork/lnd/walletunlocker"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
"golang.org/x/crypto/ssh/terminal"
|
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
@ -1340,15 +1338,13 @@ mnemonicCheck:
|
|||||||
// Additionally, the user may have a passphrase, that will also
|
// Additionally, the user may have a passphrase, that will also
|
||||||
// need to be provided so the daemon can properly decipher the
|
// need to be provided so the daemon can properly decipher the
|
||||||
// cipher seed.
|
// cipher seed.
|
||||||
fmt.Printf("Input your cipher seed passphrase (press enter if " +
|
aezeedPass, err = readPassword("Input your cipher seed " +
|
||||||
"your seed doesn't have a passphrase): ")
|
"passphrase (press enter if your seed doesn't have a " +
|
||||||
passphrase, err := terminal.ReadPassword(int(syscall.Stdin))
|
"passphrase): ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
aezeedPass = []byte(passphrase)
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Printf("Input an optional address look-ahead "+
|
fmt.Printf("Input an optional address look-ahead "+
|
||||||
@ -1460,12 +1456,10 @@ func capturePassword(instruction string, optional bool,
|
|||||||
validate func([]byte) error) ([]byte, error) {
|
validate func([]byte) error) ([]byte, error) {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
fmt.Printf(instruction)
|
password, err := readPassword(instruction)
|
||||||
password, err := terminal.ReadPassword(int(syscall.Stdin))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
fmt.Println()
|
|
||||||
|
|
||||||
// Do not require users to repeat password if
|
// Do not require users to repeat password if
|
||||||
// it is optional and they are not using one.
|
// it is optional and they are not using one.
|
||||||
@ -1481,21 +1475,16 @@ func capturePassword(instruction string, optional bool,
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Confirm password: ")
|
passwordConfirmed, err := readPassword("Confirm password: ")
|
||||||
passwordConfirmed, err := terminal.ReadPassword(
|
|
||||||
int(syscall.Stdin),
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
fmt.Println()
|
|
||||||
|
|
||||||
if bytes.Equal(password, passwordConfirmed) {
|
if bytes.Equal(password, passwordConfirmed) {
|
||||||
return password, nil
|
return password, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Passwords don't match, " +
|
fmt.Println("Passwords don't match, please try again")
|
||||||
"please try again")
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1558,13 +1547,7 @@ func unlock(ctx *cli.Context) error {
|
|||||||
// terminal to be a real tty and will fail if a string is piped into
|
// terminal to be a real tty and will fail if a string is piped into
|
||||||
// lncli.
|
// lncli.
|
||||||
default:
|
default:
|
||||||
fmt.Printf("Input wallet password: ")
|
pw, err = readPassword("Input wallet password: ")
|
||||||
|
|
||||||
// The variable syscall.Stdin is of a different type in the
|
|
||||||
// Windows API that's why we need the explicit cast. And of
|
|
||||||
// course the linter doesn't like it either.
|
|
||||||
pw, err = terminal.ReadPassword(int(syscall.Stdin)) // nolint:unconvert
|
|
||||||
fmt.Println()
|
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -1625,26 +1608,20 @@ func changePassword(ctx *cli.Context) error {
|
|||||||
client, cleanUp := getWalletUnlockerClient(ctx)
|
client, cleanUp := getWalletUnlockerClient(ctx)
|
||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
|
|
||||||
fmt.Printf("Input current wallet password: ")
|
currentPw, err := readPassword("Input current wallet password: ")
|
||||||
currentPw, err := terminal.ReadPassword(int(syscall.Stdin))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println()
|
|
||||||
|
|
||||||
fmt.Printf("Input new wallet password: ")
|
newPw, err := readPassword("Input new wallet password: ")
|
||||||
newPw, err := terminal.ReadPassword(int(syscall.Stdin))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println()
|
|
||||||
|
|
||||||
fmt.Printf("Confirm new wallet password: ")
|
confirmPw, err := readPassword("Confirm new wallet password: ")
|
||||||
confirmPw, err := terminal.ReadPassword(int(syscall.Stdin))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println()
|
|
||||||
|
|
||||||
if !bytes.Equal(newPw, confirmPw) {
|
if !bytes.Equal(newPw, confirmPw) {
|
||||||
return fmt.Errorf("passwords don't match")
|
return fmt.Errorf("passwords don't match")
|
||||||
|
Loading…
Reference in New Issue
Block a user