15 lines
421 B
Go
15 lines
421 B
Go
package utils
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
func (u *Utils) HashPassword(password string) (string, error) {
|
|
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(bytes), nil
|
|
}
|
|
|
|
func (u *Utils) ComparePasswords(hashedPassword string, plainPassword string) error {
|
|
return bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(plainPassword))
|
|
}
|