Documentation ¶
Overview ¶
Package hash provides the hash functions
Package hash provides the hash functions
Index ¶
- Variables
- func Compare(hashedPassword, password, salt string) error
- func CompareArgon2HashAndPassword(hashedPassword, password string, salt string) error
- func CompareBcryptHashAndPassword(hashedPassword, password, _ string) error
- func CompareMD5HashAndPassword(hashedPassword, password, salt string) error
- func CompareSHA1HashAndPassword(hashedPassword string, password string, salt string) error
- func CompareScryptHashAndPassword(hashedPassword, password string, salt string) error
- func Generate(password string, salt string) (string, error)
- func GenerateArgon2Password(password, salt string) (string, error)
- func GenerateBcryptPassword(password string, _ string) (string, error)
- func GenerateMD5Password(password string, salt string) (string, error)
- func GenerateSHA1Password(password string, salt string) (string, error)
- func GenerateScryptPassword(password, salt string) (string, error)
- func MD5(b []byte) string
- func MD5String(s string) string
- func SHA1(b []byte) string
- func SHA1String(s string) string
- func UseArgon2()
- func UseBcrypt()
- func UseCrypto(t Type)
- func UseMD5()
- func UseSHA1()
- func UseScrypt()
- type CompareFunc
- type GenerateAndCompare
- type GenerateFunc
- type Type
Constants ¶
This section is empty.
Variables ¶
var ErrPasswordNotMatch = errors.String("password not match")
ErrPasswordNotMatch error when password not match
Functions ¶
func Compare ¶
Compare compares the given hashed password, password, and salt with the global hash compare function. It returns an error if the comparison fails.
Parameters: - hashedPassword: the hashed password to compare. - password: the plaintext password to compare. - salt: the salt to use for the comparison.
Returns: - error: an error if the comparison fails, otherwise nil.
func CompareArgon2HashAndPassword ¶
CompareArgon2HashAndPassword compares an Argon2 hashed password with a plaintext password using a provided salt value.
Parameters: - hashedPassword: the hashed password to compare. - password: the plaintext password to compare. - salt: the salt value to use for the comparison. Returns: - error: an error if the comparison fails, otherwise nil.
func CompareBcryptHashAndPassword ¶
CompareBcryptHashAndPassword compares a bcrypt hashed password with a plaintext password.
Parameters: - hashedPassword: The hashed password to compare. - password: The plaintext password to compare. - _: Unused parameter.
Returns: - error: An error if the hashed password does not match the plaintext password.
func CompareMD5HashAndPassword ¶
CompareMD5HashAndPassword compares an MD5 hashed password with a plaintext password using a provided salt value.
Parameters: - hashedPassword: the hashed password to compare. - password: the plaintext password to compare. - salt: the salt value to use for the comparison.
Returns: - error: an error if the comparison fails, otherwise nil.
func CompareSHA1HashAndPassword ¶
CompareSHA1HashAndPassword compares a given SHA1 hashed password with a plaintext password using a provided salt value. It returns an error if the comparison fails.
Parameters: - hashedPassword: the hashed password to compare. - password: the plaintext password to compare. - salt: the salt to use for the comparison.
Returns: - error: an error if the comparison fails, otherwise nil.
func CompareScryptHashAndPassword ¶
CompareScryptHashAndPassword compares a scrypt hashed password with a plaintext password using a provided salt value.
Parameters: - hashedPassword: the hashed password to compare. - password: the plaintext password to compare. - salt: the salt value to use for the comparison.
Returns: - error: an error if the comparison fails, otherwise nil.
func Generate ¶
Generate generates a password hash using the global hash compare function.
It takes in two parameters: - password: a string representing the password to be hashed. - salt: a string representing the salt value to be used in the hashing process.
It returns a string representing the generated password hash and an error if the generation fails.
func GenerateArgon2Password ¶
GenerateArgon2Password generates an Argon2 hashed password based on the provided password and salt.
Parameters: - password: the password to hash. - salt: the salt value to use for hashing. Return type(s): a string containing the hashed password and an error.
func GenerateBcryptPassword ¶
GenerateBcryptPassword generates a bcrypt hash for the given password.
password: the password to hash. _: a placeholder for unused variable. (string, error): the generated bcrypt hash and any error encountered.
func GenerateMD5Password ¶
GenerateMD5Password generates an MD5 password hash using the provided password and salt.
Parameters: - password: the plaintext password to be hashed. - salt: the salt value to be used for hashing.
Returns: - string: the MD5 hashed password. - error: nil if the hash generation is successful, otherwise an error.
func GenerateSHA1Password ¶
GenerateSHA1Password generates a SHA1 password hash using the provided password and salt.
Parameters: - password: the plaintext password to be hashed. - salt: the salt value to be used for hashing.
Returns: - string: the SHA1 hashed password. - error: nil if the hash generation is successful, otherwise an error.
func GenerateScryptPassword ¶
GenerateScryptPassword generates a password hash using the scrypt algorithm.
Parameters: - password: the password to hash (string). - salt: the salt value to use for hashing (string).
Returns: - string: the generated password hash (hex-encoded). - error: an error if the hashing process fails.
func UseArgon2 ¶
func UseArgon2()
UseArgon2 sets the global hash compare function to the one corresponding to the TypeArgon2 hash type.
func UseBcrypt ¶
func UseBcrypt()
UseBcrypt sets the global hash compare function to the one corresponding to the TypeBcrypt hash type.
func UseCrypto ¶
func UseCrypto(t Type)
UseCrypto updates the default generate and compare functions based on the hash type provided.
t Type - the hash type to update the functions with.
func UseMD5 ¶
func UseMD5()
UseMD5 sets the global hash compare function to the one corresponding to the TypeMD5 hash type.
Types ¶
type CompareFunc ¶
CompareFunc compare password hash function
type GenerateAndCompare ¶
type GenerateAndCompare struct { Generate GenerateFunc Compare CompareFunc }
GenerateAndCompare hash type Generate and Compare functions
type GenerateFunc ¶
GenerateFunc generate password hash function