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
+11.2k Golang : Proper way to test CIDR membership of an IP 4 or 6 address example
+5.2k Golang : Issue HTTP commands to server and port example
+12.3k Golang : Simple client-server HMAC authentication without SSL example
+10.2k Golang : Find and replace data in all files recursively
+46.5k Golang : Marshal and unmarshal json.RawMessage struct example
+9.6k Golang : How to extract video or image files from html source code
+14.4k Golang : How to filter a map's elements for faster lookup
+6.1k Golang : Measure execution time for a function
+12.1k Golang : convert(cast) string to integer value
+11k Golang : Generate random elements without repetition or duplicate
+8.2k Golang : Metaprogramming example of wrapping a function