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) {
|
func getPasswordBytes() ([]byte, error) {
|
||||||
if term.IsTerminal(int(os.Stdin.Fd())) {
|
if term.IsTerminal(int(os.Stdin.Fd())) {
|
||||||
fmt.Fprintf(os.Stderr, "Enter password: ")
|
oldState, err := term.MakeRaw(0)
|
||||||
passbytes, err := term.ReadPassword(int(os.Stdin.Fd()))
|
defer term.Restore(0, oldState)
|
||||||
fmt.Println()
|
|
||||||
return passbytes, err
|
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 {
|
} else {
|
||||||
return io.ReadAll(os.Stdin)
|
return io.ReadAll(os.Stdin)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user