Skip to content

Instantly share code, notes, and snippets.

@islander
Created April 5, 2019 04:20
Show Gist options
  • Save islander/80de7606d7e07e86a4fc0fa6e203a98b to your computer and use it in GitHub Desktop.
Save islander/80de7606d7e07e86a4fc0fa6e203a98b to your computer and use it in GitHub Desktop.
Golang read password
#!/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