hash

package
v0.0.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package hash provides the hash functions

Package hash provides the hash functions

Index

Constants

This section is empty.

Variables

View Source
var ErrPasswordNotMatch = errors.String("password not match")

ErrPasswordNotMatch error when password not match

Functions

func Compare

func Compare(hashpass, password, salt string) error

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

func CompareArgon2HashAndPassword(hashpass, password string, salt string) error

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

func CompareBcryptHashAndPassword(hashpass, password, _ string) error

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 CompareMD5HashAndPassword

func CompareMD5HashAndPassword(hashpass, password, salt string) error

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

func CompareSHA1HashAndPassword(hashpass string, password string, salt string) error

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

func CompareSHA256HashAndPassword(hashpass string, password string, salt string) error

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

func CompareScryptHashAndPassword(hashpass, password string, salt string) error

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

func Generate(password string, salt string) (string, error)

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

func GenerateArgon2Password(password, salt string) (string, error)

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

func GenerateBcryptPassword(password string, _ string) (string, error)

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

func GenerateMD5Password(password string, salt string) (string, error)

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

func GenerateSHA1Password(password string, salt string) (string, error)

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

func GenerateSHA256Password(password string, salt string) (string, error)

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

func GenerateScryptPassword(password, salt string) (string, error)

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 MD5

func MD5(b []byte) []byte

MD5 hash

func MD5String

func MD5String(s string) string

MD5String md5 hash

func SHA1

func SHA1(b []byte) []byte

SHA1 sha1 hash

func SHA1String

func SHA1String(s string) string

SHA1String sha1 hash

func SHA256 added in v0.0.19

func SHA256(b []byte) []byte

SHA256 sha256 hash

func SHA256String added in v0.0.19

func SHA256String(s string) string

SHA256String sha256 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.

func UseSHA256 added in v0.0.19

func UseSHA256()

UseSHA256 sets the global hash compare function to the one corresponding to the TypeSHA256 hash type.

func UseScrypt

func UseScrypt()

UseScrypt sets the global hash compare function to the one corresponding to the TypeScrypt hash type.

Types

type CompareFunc

type CompareFunc func(hashpass, password, salt string) error

CompareFunc compare password hash function

type GenerateAndCompare

type GenerateAndCompare struct {
	Generate GenerateFunc
	Compare  CompareFunc
}

GenerateAndCompare hash type Generate and Compare functions

type GenerateFunc

type GenerateFunc func(password string, salt string) (string, error)

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"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL