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
+7.6k Golang : Progress bar with ∎ character
+7.1k Golang : Variadic function arguments sanity check example
+11.7k Golang : Drop cookie to visitor's browser and http.SetCookie() example
+7.8k Golang : Find duplicate files with filepath.Walk
+26.9k Golang : Connect to database (MySQL/MariaDB) server
+10.5k Get form post value in Go
+19.9k Golang : How to get time zone and load different time zone?
+20.9k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+6.1k Web : How to see your website from different countries?
+10.5k Swift : Convert (cast) Float to String
+20.9k Golang : Securing password with salt
+23.2k Golang : Time slice or date sort and reverse sort example