Documentation ¶
Overview ¶
Package hash provides the hash functions
Package hash provides the hash functions
Index ¶
- Constants
- func Compare(hashpass, password, salt string) error
- func CompareArgon2HashAndPassword(hashpass, password string, salt string) error
- func CompareBcryptHashAndPassword(hashpass, password, _ string) error
- func CompareHMAC256HashAndPassword(hashpass string, password string, salt string) error
- func CompareMD5HashAndPassword(hashpass, password, salt string) error
- func CompareSHA1HashAndPassword(hashpass string, password string, salt string) error
- func CompareSHA256HashAndPassword(hashpass string, password string, salt string) error
- func CompareScryptHashAndPassword(hashpass, 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 GenerateHMAC256Password(password string, salt string) (string, error)
- func GenerateMD5Password(password string, salt string) (string, error)
- func GenerateSHA1Password(password string, salt string) (string, error)
- func GenerateSHA256Password(password string, salt string) (string, error)
- func GenerateScryptPassword(password, salt string) (string, error)
- func HMAC256(b []byte, key []byte) []byte
- func HMAC256String(s string, key string) string
- func MD5(b []byte) []byte
- func MD5String(s string) string
- func SHA1(b []byte) []byte
- func SHA1String(s string) string
- func SHA256(b []byte) []byte
- func SHA256String(s string) string
- func UseArgon2()
- func UseBcrypt()
- func UseCrypto(t Type)
- func UseMD5()
- func UseSHA1()
- func UseSHA256()
- func UseScrypt()
- type CompareFunc
- type GenerateAndCompare
- type GenerateFunc
- type Type
Constants ¶
const ( // ENV environment variable name ENV = "ORIG_ADMIN_HASH_TYPE" // ErrPasswordNotMatch error when password not match ErrPasswordNotMatch = errors.String("password not match") )
Variables ¶
This section is empty.
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: - hashpass: 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: - hashpass: 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: - hashpass: 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 CompareHMAC256HashAndPassword ¶ added in v0.0.23
CompareHMAC256HashAndPassword compares an HMAC256 hashed password with a plaintext password using a provided salt value.
Parameters: - hashpass: 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 CompareMD5HashAndPassword ¶
CompareMD5HashAndPassword compares an MD5 hashed password with a plaintext password using a provided salt value.
Parameters: - hashpass: 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: - hashpass: 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 CompareSHA256HashAndPassword ¶ added in v0.0.19
CompareSHA256HashAndPassword compares an SHA256 hashed password with a plaintext password using a provided salt value.
Parameters: - hashpass: 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 CompareScryptHashAndPassword ¶
CompareScryptHashAndPassword compares a scrypt hashed password with a plaintext password using a provided salt value.
Parameters: - hashpass: 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 GenerateHMAC256Password ¶ added in v0.0.23
GenerateHMAC256Password generates an HMAC256 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 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 GenerateSHA256Password ¶ added in v0.0.19
GenerateSHA256Password generates an SHA256 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 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 HMAC256String ¶ added in v0.0.23
HMAC256String hmac256 hash
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.
func UseSHA1 ¶
func UseSHA1()
UseSHA1 sets the global hash compare function to the one corresponding to the TypeSHA1 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
type Type ¶
type Type string
Type hash type
const ( // TypeMD5 md5 type TypeMD5 Type = "md5" // TypeSHA1 sha1 type TypeSHA1 Type = "sha1" // TypeSHA256 sha256 type TypeSHA256 Type = "sha256" // TypeArgon2 argon2 type TypeArgon2 Type = "argon2" // TypeScrypt scrypt type TypeScrypt Type = "scrypt" // TypeBcrypt bcrypt type TypeBcrypt Type = "bcrypt" // TypeHMAC256 hmac sha256 type TypeHMAC256 Type = "hmac256" )