-
Notifications
You must be signed in to change notification settings - Fork 3
/
pw_dict.go
73 lines (55 loc) · 1.23 KB
/
pw_dict.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
package pitchfork
import (
"bufio"
"errors"
"os"
"strings"
)
var pw_dict map[string]bool
func Pw_checkweak_load() (err error) {
/* Put something in there */
pw_dict = make(map[string]bool)
if len(Config.PW_WeakDicts) == 0 {
Log("No Weak Password Dictionaries configured - skipping")
return
}
Dbg("Loading Weak Password Dictionaries...")
cnt := 0
for _, f := range Config.PW_WeakDicts {
cnt++
cntpw := 0
fn := System_findfile("pwdicts/", f)
if fn == "" {
err = errors.New("Could not find password dictionary file :" + f)
return
}
file, e := os.Open(fn)
if e != nil {
err = e
return
}
defer file.Close()
Dbgf("Loading Weak Password Dictionary %q...", f)
scanner := bufio.NewScanner(file)
for scanner.Scan() {
pw := scanner.Text()
/* Skip comments */
if len(pw) > 1 && pw[0] == '#' {
continue
}
pw_dict[pw] = true
cntpw++
}
err = scanner.Err()
if err != nil {
return
}
Dbgf("Loading Weak Password Dictionary %q... done (%d passwords)", f, cntpw)
}
Logf("Loaded %d Weak Password Dictionaries with %d unique passwords", cnt, len(pw_dict))
return
}
func Pw_checkweak(password string) (isweak bool) {
_, isweak = pw_dict[strings.ToLower(password)]
return
}