59 lines
925 B
Go
59 lines
925 B
Go
|
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)
|
||
|
}
|