cli: handle passwords securely

This commit is contained in:
Anna Shaleva 2022-05-12 12:06:53 +03:00
parent e87d21d396
commit 3f98449ce0
3 changed files with 55 additions and 8 deletions

View file

@ -49,15 +49,10 @@ func readLine(trm *term.Terminal, prompt string) (string, error) {
// ReadPassword reads the user's password with prompt.
func ReadPassword(prompt string) (string, error) {
trm := Terminal
if trm == nil {
s, err := term.MakeRaw(int(syscall.Stdin))
if err != nil {
return "", err
}
defer func() { _ = term.Restore(int(syscall.Stdin), s) }()
trm = term.NewTerminal(ReadWriter{os.Stdin, os.Stdout}, prompt)
if trm != nil {
return trm.ReadPassword(prompt)
}
return trm.ReadPassword(prompt)
return readSecurePassword(prompt)
}
// ConfirmTx asks for a confirmation to send the tx.