3x-ui/util/crypto/crypto.go
Columbiysky 85cbad3ef4
feat: hashing user passwords
solves problems #2944, #2783
2025-05-03 16:27:53 +07:00

15 lines
372 B
Go

package crypto
import (
"golang.org/x/crypto/bcrypt"
)
func HashPasswordAsBcrypt(password string) (string, error) {
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(hash), err
}
func CheckPasswordHash(hash, password string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}