github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/fs/config/config_read_password.go (about) 1 // ReadPassword for OSes which are supported by golang.org/x/crypto/ssh/terminal 2 // See https://github.com/golang/go/issues/14441 - plan9 3 // https://github.com/golang/go/issues/13085 - solaris 4 5 // +build !solaris,!plan9 6 7 package config 8 9 import ( 10 "fmt" 11 "log" 12 "os" 13 14 "golang.org/x/crypto/ssh/terminal" 15 ) 16 17 // ReadPassword reads a password without echoing it to the terminal. 18 func ReadPassword() string { 19 stdin := int(os.Stdin.Fd()) 20 if !terminal.IsTerminal(stdin) { 21 return ReadLine() 22 } 23 line, err := terminal.ReadPassword(stdin) 24 _, _ = fmt.Fprintln(os.Stderr) 25 if err != nil { 26 log.Fatalf("Failed to read password: %v", err) 27 } 28 return string(line) 29 }