use ssh/terminal to read a password without echo.
This commit is contained in:
parent
7fdd6d6f41
commit
5a9437f049
13
util.go
13
util.go
|
@ -29,6 +29,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
_ "humungus.tedunangst.com/r/go-sqlite3"
|
_ "humungus.tedunangst.com/r/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -71,11 +72,11 @@ func initdb() {
|
||||||
signal.Notify(c, os.Interrupt)
|
signal.Notify(c, os.Interrupt)
|
||||||
go func() {
|
go func() {
|
||||||
<-c
|
<-c
|
||||||
fmt.Printf("\x1b[?12;25h\x1b[0m")
|
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
os.Remove(dbname)
|
os.Remove(dbname)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for _, line := range strings.Split(string(schema), ";") {
|
for _, line := range strings.Split(string(schema), ";") {
|
||||||
_, err = db.Exec(line)
|
_, err = db.Exec(line)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -96,14 +97,14 @@ func initdb() {
|
||||||
log.Print("that's way too short")
|
log.Print("that's way too short")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Printf("password: \x1b[?25l\x1b[%d;%dm \x1b[16D", 30, 40)
|
fmt.Printf("password: ")
|
||||||
pass, err := r.ReadString('\n')
|
passbytes, err := terminal.ReadPassword(1)
|
||||||
fmt.Printf("\x1b[0m\x1b[?12;25h")
|
fmt.Printf("\n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Print(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pass = pass[:len(pass)-1]
|
pass := string(passbytes)
|
||||||
if len(pass) < 6 {
|
if len(pass) < 6 {
|
||||||
log.Print("that's way too short")
|
log.Print("that's way too short")
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue