Reviewed-on: phoenix/textsender-auth#6 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
24 lines
506 B
Go
24 lines
506 B
Go
package utility
|
|
|
|
import (
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
type HashMash struct {
|
|
Password string
|
|
}
|
|
|
|
func (h HashMash) HashPassword() (string, error) {
|
|
bytes, err := bcrypt.GenerateFromPassword([]byte(h.Password), bcrypt.DefaultCost)
|
|
return string(bytes), err
|
|
}
|
|
|
|
func (h HashMash) CheckPasswordHash(password string, hash string) bool {
|
|
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
|
return err == nil
|
|
}
|
|
|
|
func (h *HashMash) SetPassword(password string) {
|
|
h.Password = password
|
|
}
|