-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (40 loc) · 1.03 KB
/
main.go
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
45
46
47
48
49
50
51
package main
import (
"fmt"
flag "github.com/ogier/pflag"
"os"
)
var username *string = flag.StringP("username", "u", "", "Username to be used in .htpasswd")
var passwd *string = flag.StringP("passwd", "p", "", "Password to be used in .htpasswd")
var algo *string = flag.StringP("algo", "a", "MD5", "Algorithm to use for hashing passwords. Default: MD5")
var versionf *bool = flag.BoolP("version", "v", false, "Prints information about the tool")
var (
version = "N/A"
buildTime = "N/A"
commitId = "N/A"
)
func main() {
flag.Parse()
if *versionf {
printVersion()
os.Exit(0)
}
if len(*username) == 0 {
fmt.Fprint(os.Stderr, "Username cannot be empty\n")
os.Exit(1)
}
if len(*passwd) == 0 {
fmt.Fprint(os.Stderr, "Password cannot be empty\n")
os.Exit(1)
}
hash, err := NewHash(*algo)
if err != nil {
panic(err)
}
fmt.Println(hash.FormattedAuth(*username, *passwd))
}
func printVersion() {
fmt.Printf("Version: %s\n", version)
fmt.Printf("BuildTime: %s\n", buildTime)
fmt.Printf("CommitId: %s\n", commitId)
}