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
+9.7k Golang : Fix - does not implement sort.Interface (missing Len method)
+14.5k Golang : Read large file with bufio.Scanner cause token too long error
+5.7k Restart Apache or Nginx web server without password prompt
+17.3k Golang : Check whether a network interface is up on your machine
+3.1k Detect if Google Analytics and Developer Media are loaded properly or not
+9.5k Golang : Get local time and equivalent time in different time zone
+11.1k Golang : calculate elapsed run time
+6.3k Golang : Calculate how many weeks left to go in a given year
+12.9k Golang : concatenate(combine) strings
+22.4k Golang : Use regular expression to validate domain name
+7.9k Golang : How to get username from email address
+12k Golang : Calculate elapsed years or months since a date