aboutsummaryrefslogtreecommitdiff
path: root/cli.go
blob: df114606a61501d43355a3bcd7006e2d0cc0b24c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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)
}