all repos — honk @ 54fca0fc03dcecc585d5cfa3acf5e4a5169e8340

my fork of honk

just use tcsetattr directly instead of roundabout way
that drags in mountains of syscall code.
Ted Unangst tedu@tedunangst.com
Wed, 10 Apr 2019 18:06:04 -0400
commit

54fca0fc03dcecc585d5cfa3acf5e4a5169e8340

parent

bb60ab12011ce8c5ed92e3bd36a5ec7b9305a978

2 files changed, 22 insertions(+), 4 deletions(-)

jump to
M go.modgo.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 )
M util.goutil.go

@@ -15,6 +15,23 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

package main +/* +#include <termios.h> + +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 @@ "os/signal"

"strings" "golang.org/x/crypto/bcrypt" - "golang.org/x/crypto/ssh/terminal" _ "humungus.tedunangst.com/r/go-sqlite3" )

@@ -72,6 +88,7 @@ c := make(chan os.Signal)

signal.Notify(c, os.Interrupt) go func() { <-c + C.termecho(1) fmt.Printf("\n") os.Remove(dbname) os.Exit(1)

@@ -97,14 +114,16 @@ if len(name) < 1 {

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