We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 17946ac commit 0acfdadCopy full SHA for 0acfdad
utils/auth.go
@@ -0,0 +1,16 @@
1
+package utils
2
+
3
+import "golang.org/x/crypto/bcrypt"
4
5
+func HashPassword(password string) (string, error) {
6
+ hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
7
+ if err != nil {
8
+ return "", err
9
+ }
10
+ return string(hash), nil
11
+}
12
13
+func ComparePasswords(hashed string, plain []byte) bool {
14
+ err := bcrypt.CompareHashAndPassword([]byte(hashed), plain)
15
+ return err == nil
16
utils/utils.go renamed to utils/http.go
@@ -42,4 +42,5 @@ func GetTokenFromRequest(r *http.Request) string {
42
}
43
44
return ""
45
46
0 commit comments