-
Notifications
You must be signed in to change notification settings - Fork 0
/
pass_guess2.go
55 lines (46 loc) · 1.04 KB
/
pass_guess2.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
/*This program reads in a wordlist and selects a random guess word*/
package main
import (
"fmt" // For Printing
"os" // For error handling
"bufio"// To read the wordlist
"time" // To use as a rand.Seed Arg
"math/rand" // For picking a word
)
func main() {
rand.Seed(time.Now().UnixNano())
var input string
fmt.Print("Enter password: ")
_, err :=fmt.Scanln(&input)
if err != nil {
fmt.Println("Error:",err.Error())
os.Exit(0)
}
generated := random_gen()
if !(input == generated) {
fmt.Println("Wrong Password!")
fmt.Println("Password:",generated)
os.Exit(0)
} else { fmt.Println("Access granted!") }
}
func random_gen() string {
f, err := os.Open("namelist.txt")
if err != nil {
fmt.Println("Error:",err.Error())
os.Exit(0)
}
scanner := bufio.NewScanner(f)
scanner.Split(bufio.ScanWords)
var pass []string
for scanner.Scan() {
pass = append(pass, scanner.Text())
}
var p *string
for {
p = &pass[rand.Intn(len(pass))]
if !(len(*p) > 4) {
p = &pass[rand.Intn(len(pass))]
} else { break }
}
return *p
}