crypt.go 548 B

12345678910111213141516171819202122232425
  1. package internals
  2. import (
  3. "golang.org/x/crypto/bcrypt"
  4. )
  5. type Crypt struct {
  6. initialized bool
  7. }
  8. func NewCrypt() *Crypt {
  9. return &Crypt{initialized: true}
  10. }
  11. func (c *Crypt) HashPassword(password string) (string, error) {
  12. appended_password := password
  13. bytes, err := bcrypt.GenerateFromPassword([]byte(appended_password), 14)
  14. return string(bytes), err
  15. }
  16. func (c *Crypt) CheckPasswordHash(password string, hash string) error {
  17. appended_password := password
  18. return bcrypt.CompareHashAndPassword([]byte(hash), []byte(appended_password))
  19. }