mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-10-13 11:39:13 +00:00
18 lines
610 B
Go
18 lines
610 B
Go
// Package crypto provides cryptographic utilities for password hashing and verification.
|
|
package crypto
|
|
|
|
import (
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
// HashPasswordAsBcrypt generates a bcrypt hash of the given password.
|
|
func HashPasswordAsBcrypt(password string) (string, error) {
|
|
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
|
return string(hash), err
|
|
}
|
|
|
|
// CheckPasswordHash verifies if the given password matches the bcrypt hash.
|
|
func CheckPasswordHash(hash, password string) bool {
|
|
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
|
return err == nil
|
|
}
|