2022-03-31 05:13:53 +08:00
|
|
|
// ReadPassword for OSes which are supported by golang.org/x/term
|
2016-02-21 18:31:53 +08:00
|
|
|
// See https://github.com/golang/go/issues/14441 - plan9
|
|
|
|
|
2022-03-31 05:13:53 +08:00
|
|
|
//go:build !plan9
|
2016-02-21 18:31:53 +08:00
|
|
|
|
2018-01-13 00:30:54 +08:00
|
|
|
package config
|
2016-02-21 18:31:53 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2024-08-18 22:58:35 +08:00
|
|
|
"github.com/rclone/rclone/fs"
|
2020-08-01 02:57:48 +08:00
|
|
|
"github.com/rclone/rclone/lib/terminal"
|
2016-02-21 18:31:53 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
2024-08-18 22:58:35 +08:00
|
|
|
fs.Fatalf(nil, "Failed to read password: %v", err)
|
2016-02-21 18:31:53 +08:00
|
|
|
}
|
2017-10-19 19:36:12 +08:00
|
|
|
return string(line)
|
2016-02-21 18:31:53 +08:00
|
|
|
}
|