Created
April 5, 2019 04:20
-
-
Save islander/80de7606d7e07e86a4fc0fa6e203a98b to your computer and use it in GitHub Desktop.
Golang read password
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env gorun | |
package main | |
import ( | |
"fmt" | |
"syscall" | |
"golang.org/x/crypto/ssh/terminal" | |
) | |
func main() { | |
fmt.Println("Your password: ") | |
bytePassword, _ := terminal.ReadPassword(int(syscall.Stdin)) | |
password := string(bytePassword) | |
fmt.Println() // it's necessary to add a new line after user's input | |
fmt.Printf("Your password has leaked, it is '%s'", password) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment