2024-03-19 16:20:32 +00:00
|
|
|
package hash
|
|
|
|
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
|
|
|
|
func HashPassword(password string, cost int) (string, error) {
|
|
|
|
bytes, err := bcrypt.GenerateFromPassword([]byte(password), cost)
|
|
|
|
return string(bytes), err
|
|
|
|
}
|
|
|
|
|
2024-03-21 20:10:56 +00:00
|
|
|
func CheckPasswordHash(password, hash string) error {
|
|
|
|
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
2024-03-19 16:20:32 +00:00
|
|
|
}
|