2016-02-21 18:31:53 +08:00
|
|
|
// ReadPassword for OSes which are supported by golang.org/x/crypto/ssh/terminal
|
|
|
|
// See https://github.com/golang/go/issues/14441 - plan9
|
|
|
|
// https://github.com/golang/go/issues/13085 - solaris
|
|
|
|
|
|
|
|
// +build !solaris,!plan9
|
|
|
|
|
2018-01-13 00:30:54 +08:00
|
|
|
package config
|
2016-02-21 18:31:53 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"golang.org/x/crypto/ssh/terminal"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ReadPassword reads a password without echoing it to the terminal.
|
|
|
|
func ReadPassword() string {
|
2018-06-28 18:54:15 +08:00
|
|
|
stdin := int(os.Stdin.Fd())
|
|
|
|
if !terminal.IsTerminal(stdin) {
|
|
|
|
return ReadLine()
|
|
|
|
}
|
|
|
|
line, err := terminal.ReadPassword(stdin)
|
2018-05-22 16:41:13 +08:00
|
|
|
_, _ = fmt.Fprintln(os.Stderr)
|
2016-02-21 18:31:53 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to read password: %v", err)
|
|
|
|
}
|
2017-10-19 19:36:12 +08:00
|
|
|
return string(line)
|
2016-02-21 18:31:53 +08:00
|
|
|
}
|