Documentation
¶
Index ¶
- Variables
- func BcryptCost(hashedPassword string) (cost int, err error)
- func CompareBcryptPasswordAndHash(plaintextPassword, hashedPassword string) (match bool, err error)
- func ComparePasswordAndHash(plaintextPassword, hashedPassword string) (match bool, err error)
- func GenerateOTP(length int) (string, error)
- func GeneratePassword(params ...GeneratePasswordOptions) (string, error)
- func Hash(plaintextPassword string, cost ...int) (string, error)
- func HashWithBcrypt(plaintextPassword string, cost ...int) (string, error)
- func IsCommon(value string) bool
- func Validate(value string) (bool, []string)
- type GeneratePasswordOptions
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyPassword is returned by Hash* if the provided // plaintextPassword is "" ErrEmptyPassword = errors.New("password cannot be empty") // ErrPasswordTooShort is returned by Validate if the provided // password is less than 8 characters ErrPasswordTooShort = errors.New("password must be at least 8 characters long") // ErrPasswordTooLong is returned by Validate and Hash* functions if the provided // password is more than 72 characters ErrPasswordTooLong = errors.New("password length exceeds 72 characters") // ErrPasswordShouldHaveUppercase is returned by Validate if the provided // password does not have an uppercase letter ErrPasswordShouldHaveUppercase = errors.New("password must contain at least one uppercase letter") // ErrPasswordShouldHaveUppercase is returned by Validate if the provided // password does not have an uppercase letter ErrPasswordShouldHaveLowercase = errors.New("password must contain at least one lowercase letter") // ErrPasswordShouldHaveDigit is returned by Validate if the provided // password does not have a digit letter ErrPasswordShouldHaveDigit = errors.New("password must contain at least one number") // ErrPasswordShouldHaveSpecialChar is returned by Validate if the provided // password does not have a special character ErrPasswordShouldHaveSpecialChar = errors.New("password must contain at least one special character") // ErrPasswordTooCommon is returned by Validate if the provided // password is passed to IsCommon, which then returns true ErrPasswordTooCommon = errors.New("password is too common, please choose a stronger one") // ErrInvalidOTPLength is returned by GenerateOTP if the provided // length is less than 4 ErrInvalidOTPLength = errors.New("OTP length must be at least 4 digits") )
var CommonPasswords = []string{}/* 10000 elements not displayed */
CommonPasswords list is from https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/10k-most-common.txt
Functions ¶
func BcryptCost ¶
BcryptCost gets the bcrypt cost factor from a hashed password. Returns the cost factor or an error if the extraction fails.
func CompareBcryptPasswordAndHash ¶
CompareBcryptPasswordAndHash compares a plaintext password with a bcrypt hash. Returns true if they match, false if they don't, and an error if something goes wrong.
func ComparePasswordAndHash ¶
ComparePasswordAndHash verifies a plaintext password against a hashed password. It uses Bcrypt as default Returns true if they match, false otherwise.
func GenerateOTP ¶
GenerateOTP generates a one-time password (OTP) of the specified length. The OTP consists only of numeric digits (0-9).
Returns the generated OTP as a string or an error if the length is invalid.
func GeneratePassword ¶ added in v1.1.4
func GeneratePassword(params ...GeneratePasswordOptions) (string, error)
GeneratePassword randomly generates a secure password, It has options for customizing it's behavior, option is used when custom isn't given
Returns the generated password as a string or an error if there's any
func HashWithBcrypt ¶
HashWithBcrypt hashes a password using bcrypt it ensures the password is not empty and not more than 72 characters. There is an optional parameter for specifying the cost
func IsCommon ¶
IsCommon checks if the provided password is present in a list of 10k commonly used passwords see https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/10k-most-common.txt
func Validate ¶
Validate checks the strength of a password based on the following criteria: - Minimum length of 8 characters - Maximum length of 72 characters (bcrypt limitation) - At least one uppercase letter - At least one lowercase letter - At least one number - At least one special character - Is not common password
It returns a boolean indicating validity and a slice of strings describing any issues.