-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwnpass.go
79 lines (70 loc) · 1.86 KB
/
pwnpass.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"github.com/howeyc/gopass"
"github.com/masonj188/pwchecker"
)
func printResults(isHidden, isPwned bool, checkedPass, numTimes string) {
if isPwned {
if isHidden {
fmt.Printf("This password has been pwned %s time(s)\n", numTimes)
} else {
fmt.Printf("The password: %s has been pwned %s time(s)\n", checkedPass, numTimes)
}
} else {
if isHidden {
fmt.Printf("This password has not been pwned\n")
} else {
fmt.Printf("The password: %s has NOT been pwned\n", checkedPass)
}
}
}
func main() {
// Parse flags for batch processing or cli single entry
clPntr := flag.String("p", "none", "Plain text password to check")
batchPntr := flag.String("batch", "none", "Input path of file to be batch processed")
flag.Parse()
// Get password input if not batch processing
if *batchPntr == "none" && *clPntr == "none" {
fmt.Printf("Password: ")
passwd, err := gopass.GetPasswd()
if err != nil {
fmt.Println("Error parsing password")
}
rpwd, err := pwchecker.CheckForPwnage(string(passwd))
if err != nil {
fmt.Println("Couldn't return processed password")
panic(err)
}
printResults(true, rpwd.Pwnd, rpwd.Pwd, rpwd.TmPwnd)
} else if *clPntr == "none" {
file, err := os.Open(*batchPntr)
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
rpwd, err := pwchecker.CheckForPwnage(scanner.Text())
if err != nil {
fmt.Println("Couldn't return processed password")
panic(err)
}
printResults(false, rpwd.Pwnd, rpwd.Pwd, rpwd.TmPwnd)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
} else {
rpwd, err := pwchecker.CheckForPwnage(*clPntr)
if err != nil {
fmt.Println("Couldn't return processed password")
panic(err)
}
printResults(false, rpwd.Pwnd, rpwd.Pwd, rpwd.TmPwnd)
}
}