From 968daeb12fc4efb42043f1804fc45527a61f2f8f Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Sun, 26 May 2019 16:01:55 -0700 Subject: [PATCH] [wallet] ask for passphrase twice (#881) Signed-off-by: Leo Chen --- cmd/client/wallet/main.go | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/cmd/client/wallet/main.go b/cmd/client/wallet/main.go index 346b78083..c2fcb9c7d 100644 --- a/cmd/client/wallet/main.go +++ b/cmd/client/wallet/main.go @@ -9,11 +9,8 @@ import ( "math/rand" "os" "path" - "syscall" "time" - "golang.org/x/crypto/ssh/terminal" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" @@ -245,30 +242,18 @@ func createWalletNode() *node.Node { return w } -func getPassphrase(prompt string) string { - fmt.Printf(prompt) - bytePassword, err := terminal.ReadPassword(int(syscall.Stdin)) - if err != nil { - panic("read password error") - } - password := string(bytePassword) - fmt.Println() - return password -} - func processNewCommnad() { newCommand.Parse(os.Args[2:]) noPass := *newCommandNoPassPtr password := "" if !noPass { - fmt.Printf("Passphrase: ") - bytePassword, err := terminal.ReadPassword(int(syscall.Stdin)) - if err != nil { - panic("read password error") + password := utils.AskForPassphrase("Passphrase: ") + password2 := utils.AskForPassphrase("Passphrase again: ") + if password != password2 { + fmt.Printf("Passphrase doesn't match. Please try again!\n") + os.Exit(3) } - password = string(bytePassword) - fmt.Println() } account, err := ks.NewAccount(password) @@ -290,8 +275,8 @@ func processListCommand() { password := "" newpass := "" if !noPass { - password = getPassphrase("Passphrase: ") - newpass = getPassphrase("Export Passphrase: ") + password = utils.AskForPassphrase("Passphrase: ") + newpass = utils.AskForPassphrase("Export Passphrase: ") } data, err := ks.Export(account, password, newpass) if err == nil {