aboutsummaryrefslogtreecommitdiff
path: root/cli.go
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2023-09-25 10:27:49 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2023-09-25 10:27:49 +0200
commitd0ed765be72f80034fa530ba037e488c35abdd9e (patch)
treed9138f978d9521bd7f5fb5ec53b37a99abb59159 /cli.go
parent5b246ec86bc3eee768da2347f031b349d1e1553d (diff)
downloadguichet-d0ed765be72f80034fa530ba037e488c35abdd9e.tar.gz
guichet-d0ed765be72f80034fa530ba037e488c35abdd9e.zip
add a cli feature
Diffstat (limited to 'cli.go')
-rw-r--r--cli.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/cli.go b/cli.go
new file mode 100644
index 0000000..df11460
--- /dev/null
+++ b/cli.go
@@ -0,0 +1,44 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os"
+ "syscall"
+ "golang.org/x/term"
+)
+
+var fsCli = flag.NewFlagSet("cli", flag.ContinueOnError)
+var passFlag = fsCli.Bool("passwd", false, "Tool to generate a guichet-compatible password hash")
+
+func cliMain(args []string) {
+ if err := fsCli.Parse(args); err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+
+ if *passFlag {
+ cliPasswd()
+ } else {
+ fsCli.PrintDefaults()
+ os.Exit(1)
+ }
+}
+
+func cliPasswd() {
+ fmt.Print("Password: ")
+ bytepw, err := term.ReadPassword(int(syscall.Stdin))
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+ pass := string(bytepw)
+
+ hash, err := SSHAEncode(pass)
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+
+ fmt.Println(hash)
+}