hashing.go 376 B

123456789101112131415
  1. package utils
  2. import (
  3. "golang.org/x/crypto/bcrypt"
  4. )
  5. func HashPassword(password string) (string, error) {
  6. // 0 will use the default cost of 10 instead
  7. hash, err := bcrypt.GenerateFromPassword([]byte(password), 0)
  8. return string(hash), err
  9. }
  10. func ComparseHash(hash string, password string) error {
  11. return bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
  12. }