-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.go
More file actions
50 lines (43 loc) · 829 Bytes
/
common.go
File metadata and controls
50 lines (43 loc) · 829 Bytes
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
package hunter2
import (
"bufio"
"log"
"os"
)
// TODO: Fix this path for importing...
const defaultFilePath = "./passwords.txt"
// Common ...
type Common interface {
IsCommon(password string) bool
IsNotCommon(password string) bool
}
// Passwords ...
type Passwords struct {
List *os.File
}
// IsCommon ...
func (p *Passwords) IsCommon(password string) bool {
scanner := bufio.NewScanner(p.List)
for scanner.Scan() {
if scanner.Text() == password {
return true
}
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
defer p.List.Close()
return false
}
// IsNotCommon ...
func (p *Passwords) IsNotCommon(password string) bool {
return !p.IsCommon(password)
}
// New ...
func New() *Passwords {
file, err := os.Open(defaultFilePath)
if err != nil {
log.Fatal(err)
}
return &Passwords{file}
}