Skip to content

Commit a57c989

Browse files
committed
bcrypt example
1 parent 17e3852 commit a57c989

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

000_temp/51_bcrypt/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"golang.org/x/crypto/bcrypt"
5+
"fmt"
6+
)
7+
8+
func main() {
9+
s := `password123`
10+
bs, err := bcrypt.GenerateFromPassword([]byte(s), bcrypt.MinCost)
11+
if err != nil {
12+
fmt.Println(err)
13+
}
14+
fmt.Println(s)
15+
fmt.Println(bs)
16+
17+
loginPword1 := `password1234`
18+
19+
err = bcrypt.CompareHashAndPassword(bs, []byte(loginPword1))
20+
if err != nil {
21+
fmt.Println("YOU CAN'T LOGIN")
22+
return
23+
}
24+
25+
fmt.Println("You're logged in")
26+
}

0 commit comments

Comments
 (0)