Files
2026-05-10 12:21:27 +08:00

19 lines
422 B
Go

package crypto
import "golang.org/x/crypto/bcrypt"
const bcryptCost = 12
func hashPasswordBcrypt(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcryptCost)
if err != nil {
return "", err
}
return string(bytes), nil
}
func verifyPasswordBcrypt(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}