Situation:
I want to get a password entry from the stdin
console - without echoing what the user types. Is there something comparable to getpasswd
functionality in Go?
What I tried:
I tried using syscall.Read
, but it echoes what is typed.
Situation:
I want to get a password entry from the stdin
console - without echoing what the user types. Is there something comparable to getpasswd
functionality in Go?
What I tried:
I tried using syscall.Read
, but it echoes what is typed.
The following is one of best ways to get it done. First get
terminal
package bygo get golang.org/x/crypto/ssh
http://play.golang.org/p/l-9IP1mrhA
Required launching stty via Go ForkExec() function:
You can get the behavior you want with the Read method from the os.File object (or the os.Stdin variable). The following sample program will read a line of text (terminated with by pressing the return key) but won't echo it until the fmt.Printf call.
If you want more advanced behavior, you're probably going to have to use the Go C-wrapper utilities and create some wrappers for low-level api calls.