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
+26.4k Golang : Move file to another directory
+4.5k Swift : Convert string array to array example
+9.5k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+6.4k Golang : Create zip/ePub file without compression(use Store algorithm)
+17.1k Golang : Logging with logrus
+17.2k Golang : Send email with attachment
+5.1k Golang : Extract XML attribute data with attr field tag example
+31.6k Delete a directory in Go
+16.5k Golang : Aligning strings to right, left and center with fill example
+7.7k Golang : Accept any number of function arguments with three dots(...)
+8.8k Golang : Check if user agent is a robot or crawler example
+14k Golang : Force download file example