hash.go 331 B

123456789101112131415
  1. package hash
  2. import (
  3. "golang.org/x/crypto/bcrypt"
  4. )
  5. func HashPassword(password string) string {
  6. bytes, _ := bcrypt.GenerateFromPassword([]byte(password), 14)
  7. return string(bytes)
  8. }
  9. func CheckPasswordHash(password, hash string) bool {
  10. err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
  11. return err == nil
  12. }