use ssh/terminal to read a password without echo.
Ted Unangst tedu@tedunangst.com
Wed, 10 Apr 2019 08:16:29 -0400
1 files changed,
7 insertions(+),
6 deletions(-)
jump to
M
util.go
→
util.go
@@ -29,6 +29,7 @@ "os/signal"
"strings" "golang.org/x/crypto/bcrypt" + "golang.org/x/crypto/ssh/terminal" _ "humungus.tedunangst.com/r/go-sqlite3" )@@ -71,11 +72,11 @@ c := make(chan os.Signal)
signal.Notify(c, os.Interrupt) go func() { <-c - fmt.Printf("\x1b[?12;25h\x1b[0m") fmt.Printf("\n") os.Remove(dbname) os.Exit(1) }() + for _, line := range strings.Split(string(schema), ";") { _, err = db.Exec(line) if err != nil {@@ -96,14 +97,14 @@ if len(name) < 1 {
log.Print("that's way too short") return } - fmt.Printf("password: \x1b[?25l\x1b[%d;%dm \x1b[16D", 30, 40) - pass, err := r.ReadString('\n') - fmt.Printf("\x1b[0m\x1b[?12;25h") + fmt.Printf("password: ") + passbytes, err := terminal.ReadPassword(1) + fmt.Printf("\n") if err != nil { - log.Fatal(err) + log.Print(err) return } - pass = pass[:len(pass)-1] + pass := string(passbytes) if len(pass) < 6 { log.Print("that's way too short") return