-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathpassword.go
More file actions
33 lines (27 loc) · 712 Bytes
/
password.go
File metadata and controls
33 lines (27 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//
// password is an example of reading a password from standard in
// without echoing it back to the user.
//
package main
import (
"fmt"
"golang.org/x/crypto/ssh/terminal"
"os"
)
func main() {
stdin := 1
fmt.Fprintf(os.Stdin, "Enter a test password: ")
// Get current state of terminal
// s, err := terminal.MakeRaw(stdin)
// check(err, "making raw terminal, Saving old terminal state")
// defer terminal.Restore(stdin, s)
// Read password from stdin
b, err := terminal.ReadPassword(stdin)
check(err, "reading from terminal")
fmt.Println("Your test password is:", string(b))
}
func check(err error, action string) {
if err != nil {
fmt.Printf("Error %s: %v\n", action, err)
}
}