-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
33 lines (25 loc) · 777 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
package main
import (
"fmt"
"golang.org/x/crypto/bcrypt"
)
func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
return string(bytes), err
}
func CheckPasswordHash(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}
func main() {
var password string
fmt.Println("Your Password should not contain any spaces")
fmt.Print("Please enter your password: ")
fmt.Scanln(&password)
hash, _ := HashPassword(password)
fmt.Println("Password:", password)
fmt.Println("Hashed Password: ", hash)
match := CheckPasswordHash(password, hash)
fmt.Println("Match: ", match)
}
// Decryption of hashed password algorithm is comming soon....