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