You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
407 B

  1. package Auth
  2. import (
  3. "golang.org/x/crypto/bcrypt"
  4. )
  5. func HashPassword(password string) (string, error) {
  6. var (
  7. bytes []byte
  8. err error
  9. )
  10. bytes, err = bcrypt.GenerateFromPassword([]byte(password), 14)
  11. return string(bytes), err
  12. }
  13. func CheckPasswordHash(password, hash string) bool {
  14. var (
  15. err error
  16. )
  17. err = bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
  18. return err == nil
  19. }