From 6c05424ee52867b563b2cc1dc9b68619522a9eee Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Tue, 21 May 2019 21:07:44 -0700 Subject: [PATCH] [utils] add a function to ask user for passphrase Signed-off-by: Leo Chen --- internal/utils/passphrase.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 internal/utils/passphrase.go diff --git a/internal/utils/passphrase.go b/internal/utils/passphrase.go new file mode 100644 index 000000000..03206e838 --- /dev/null +++ b/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 +}