[utils] add a function to ask user for passphrase

Signed-off-by: Leo Chen <leo@harmony.one>
pull/845/head
Leo Chen 6 years ago
parent eab04af9c9
commit 6c05424ee5
  1. 21
      internal/utils/passphrase.go

@ -0,0 +1,21 @@
package utils
import (
"fmt"
"syscall"
"golang.org/x/crypto/ssh/terminal"
)
// AskForPassphrase return passphrase using password input
func AskForPassphrase(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
}
Loading…
Cancel
Save