Password script

This commit is contained in:
Lukas Bachschwell 2018-11-13 19:03:08 +01:00
parent cbdb6dc339
commit 1fd3c77194
1 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,58 @@
package main
import (
"bufio"
"fmt"
"multitenantStack/services/tokenTools"
"os"
"os/exec"
)
func raw(start bool) error {
r := "raw"
if !start {
r = "-raw"
}
rawMode := exec.Command("stty", r)
rawMode.Stdin = os.Stdin
err := rawMode.Run()
if err != nil {
return err
}
return rawMode.Wait()
}
// http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html
func main() {
fmt.Println("Enter a password and press enter:")
var rs []rune
raw(true)
for {
inp := bufio.NewReader(os.Stdin)
r, _, err := inp.ReadRune()
if err != nil {
raw(false)
panic(err)
}
if r == '\x03' { // ctrl+c
break
} else if r == '\r' { // enter
raw(false)
//fmt.Print(string(rs), "\n\r")
fmt.Println(tokenTools.HashPassword(string(rs)))
//rs = []rune{}
os.Exit(0)
continue
} else if r == '\u007f' { // backspace
fmt.Printf("\033[1D\033[K")
continue
}
rs = append(rs, r)
}
raw(false)
}