Golang : Get password from console input without echo or masked
Found this package https://github.com/howeyc/gopass that allows Golang developers to build text based application that takes in password without echo(silent mode) or use masking.
For example :
package main
import (
"fmt"
"github.com/howeyc/gopass"
)
func main() {
fmt.Printf("Enter silent password: ")
silentPassword := gopass.GetPasswd() // Silent
// input is in byte and need to convert to string
// for storing and comparison
fmt.Println(string(silentPassword))
fmt.Printf("Enter masked password: ")
maskedPassword := gopass.GetPasswdMasked() // Masked
fmt.Println(string(maskedPassword))
}
Sample output :
Enter silent password:
abc
Enter masked password: ********
abc12345
See also : Golang : Bcrypting password
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+6.8k Nginx : How to block user agent ?
+30.9k Golang : Get local IP and MAC address
+10.7k Golang : Intercept and process UNIX signals example
+4.5k HTTP common errors and their meaning explained
+5.1k Swift : Convert string array to array example
+9.3k Golang : Populate slice with sequential integers example
+22.6k Golang : Get ASCII code from a key press(cross-platform) example
+14.1k Golang : How to get URL port?
+10.8k CodeIgniter : How to check if a session exist in PHP?
+19.4k Golang : Count JSON objects and convert to slice/array
+5.7k PHP : How to check if an array is empty ?