/
main.go
49 lines (36 loc) · 788 Bytes
/
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
package main
import (
"bufio"
"fmt"
"log"
"os"
"time"
"golang.org/x/crypto/bcrypt"
)
func main() {
start := time.Now()
lines := 0
file, err := os.Open("quotes.txt")
if err != nil {
log.Fatal(err)
}
scanner := bufio.NewScanner(file)
// optionally, resize scanner's capacity for lines over 64K, see next example
for scanner.Scan() {
lines++
quote := scanner.Text()
password := []byte(quote)
hashedPassword := hash(password)
fmt.Println(string(hashedPassword))
}
fmt.Println(lines, "hashes have been generated")
fmt.Printf("time: %s", time.Since(start))
}
func hash(password []byte) []byte {
hashedPassword, err := bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
return hashedPassword
}