1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
package prompt
import (
"syscall"
"github.com/liamg/clinch/terminal"
sshterm "golang.org/x/crypto/ssh/terminal"
)
// EnterPassword requests input from the user with the given message, hiding that input, and returns any user input that was gathered until a newline was entered
func EnterPassword(msg string) string {
terminal.ClearLine()
terminal.PrintImportantf(msg)
bytePassword, err := sshterm.ReadPassword(int(syscall.Stdin))
if err != nil {
return ""
}
return string(bytePassword)
}
// EnterPasswordE requests input from the user with the given message, hiding that input, and returns any user input that was gathered until a newline was entered - returning an error if one occurred
func EnterPasswordE(msg string) (string, error) {
terminal.ClearLine()
terminal.PrintImportantf(msg)
bytePassword, err := sshterm.ReadPassword(int(syscall.Stdin))
if err != nil {
return "", err
}
return string(bytePassword), nil
}
|