change password input method
in previous method if press ctrl-c during password enter terminal echo kept off. It was possible to fix it to set `stty echo` in sigint handler, but this solution is more elegant
This commit is contained in:
parent
d5192456ce
commit
5f13d1d409
@ -180,10 +180,17 @@ func isEntropyValid(passbytes []byte, entropyLevel int) bool {
|
||||
|
||||
func getPasswordBytes() ([]byte, error) {
|
||||
if term.IsTerminal(int(os.Stdin.Fd())) {
|
||||
fmt.Fprintf(os.Stderr, "Enter password: ")
|
||||
passbytes, err := term.ReadPassword(int(os.Stdin.Fd()))
|
||||
fmt.Println()
|
||||
return passbytes, err
|
||||
oldState, err := term.MakeRaw(0)
|
||||
defer term.Restore(0, oldState)
|
||||
|
||||
screen := struct {
|
||||
io.Reader
|
||||
io.Writer
|
||||
}{os.Stdin, os.Stdout}
|
||||
t := term.NewTerminal(screen, "")
|
||||
pass, err := t.ReadPassword("Enter pass: ")
|
||||
|
||||
return []byte(pass), err
|
||||
} else {
|
||||
return io.ReadAll(os.Stdin)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user