Skip to content

Commit 0acfdad

Browse files
committed
chore(utils): create auth and http utilities
1 parent 17946ac commit 0acfdad

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

utils/auth.go

+16
Original file line numberDiff line numberDiff line change
@@ -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

+1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ func GetTokenFromRequest(r *http.Request) string {
4242
}
4343

4444
return ""
45+
4546
}

0 commit comments

Comments
 (0)