softplayer-backend/internal/helpers/hash/hash.go

14 lines
355 B
Go
Raw Normal View History

package hash
import "golang.org/x/crypto/bcrypt"
func HashPassword(password string, cost int) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), cost)
return string(bytes), err
}
func CheckPasswordHash(password, hash string) bool {
2024-03-21 17:39:32 +00:00
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}