From 320666a13107430d8495561a092414c8b909797d Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Wed, 10 Apr 2019 18:06:04 -0400 Subject: [PATCH] just use tcsetattr directly instead of roundabout way that drags in mountains of syscall code. --- go.mod | 1 - util.go | 25 ++++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 689e8df..63d0423 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,5 @@ require ( github.com/gorilla/mux v1.7.1 golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5 golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 - golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e humungus.tedunangst.com/r/go-sqlite3 v1.1.2 ) diff --git a/util.go b/util.go index 17ea8af..a25de4f 100644 --- a/util.go +++ b/util.go @@ -15,6 +15,23 @@ package main +/* +#include + +void +termecho(int on) +{ + struct termios t; + tcgetattr(1, &t); + if (on) + t.c_lflag |= ECHO; + else + t.c_lflag &= ~ECHO; + tcsetattr(1, TCSADRAIN, &t); +} +*/ +import "C" + import ( "bufio" "crypto/rand" @@ -29,7 +46,6 @@ import ( "strings" "golang.org/x/crypto/bcrypt" - "golang.org/x/crypto/ssh/terminal" _ "humungus.tedunangst.com/r/go-sqlite3" ) @@ -72,6 +88,7 @@ func initdb() { signal.Notify(c, os.Interrupt) go func() { <-c + C.termecho(1) fmt.Printf("\n") os.Remove(dbname) os.Exit(1) @@ -97,14 +114,16 @@ func initdb() { log.Print("that's way too short") return } + C.termecho(0) fmt.Printf("password: ") - passbytes, err := terminal.ReadPassword(1) + pass, err := r.ReadString('\n') + C.termecho(1) fmt.Printf("\n") if err != nil { log.Print(err) return } - pass := string(passbytes) + pass = pass[:len(pass)-1] if len(pass) < 6 { log.Print("that's way too short") return