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
M
util.go
→
util.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