feat: hashing user passwords

solves problems #2944, #2783
This commit is contained in:
Columbiysky
2025-05-03 12:27:53 +03:00
committed by GitHub
parent 3d54e33051
commit 85cbad3ef4
5 changed files with 101 additions and 10 deletions

15
util/crypto/crypto.go Normal file
View File

@@ -0,0 +1,15 @@
package crypto
import (
"golang.org/x/crypto/bcrypt"
)
func HashPasswordAsBcrypt(password string) (string, error) {
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(hash), err
}
func CheckPasswordHash(hash, password string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}