-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/crypto/ssh/terminal: ReadPassword keeps echo disabled when stopped with Ctrl+C #31180
Comments
I thought this is normal behavior with other similar programs too. |
This comment has been minimized.
This comment has been minimized.
Doesn't seem to be the behavior for |
Removed Linux from the description as I cannot reproduce it on Linux with go1.12.1. |
Actually, I can reproduce on Linux. |
It seems to depend on the shell. Cannot reproduce with |
I was able to reproduce with go version go1.13.7 linux/amd64 |
I got the exact same issue and found a way to fix it, based on this thread: https://groups.google.com/g/golang-nuts/c/DCl8xUJMJJ0. import (
"os"
"os/signal"
"syscall"
"golang.org/x/term"
)
func ReadPassword() (string, error) {
stdin := int(syscall.Stdin)
oldState, err := term.GetState(stdin)
if err != nil {
return "", err
}
defer term.Restore(stdin, oldState)
sigch := make(chan os.Signal, 1)
signal.Notify(sigch, os.Interrupt)
go func() {
for _ = range sigch {
term.Restore(stdin, oldState)
os.Exit(1)
}
}()
password, err := term.ReadPassword(stdin)
if err != nil {
return "", err
}
return string(password), nil
} Calling that Also, based on that PR: https://go-review.googlesource.com/c/crypto/+/258003/, I believe we should use Hope that helps. |
I reproduced this bug with |
The issue should be renamed to @norbjd Personally I think your code is exactly the solution to this issue. How about making a pull request? So that the implementation of |
@SadPencil I'm not sure but I think my code does not work on Windows. I'll take a look 👍 |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?Linux and macOS
What did you do?
Tried to use the following code to read passwords (from https://qiita.com/moutend/items/12d53750363edbbc3d6b):
What did you expect to see?
If I press Ctrl+C at the point when I'm supposed to enter password I'm expecting my terminal back working as before running the code.
What did you see instead?
I'm unable to see what I'm typing anymore as echo is kept disabled
The text was updated successfully, but these errors were encountered: