Documentation ¶
Overview ¶
Package securepassword implements a password generator and check.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTooFewWords represents an error thrown if the password will // have fewer than four words and are not considered to be safe ErrTooFewWords = errors.New("XKCD passwords with less than 4 words makes no sense") // DefaultXKCD contains an default instance of the XKCD password // generator DefaultXKCD = NewXKCDGenerator() )
var ErrLengthTooLow = errors.New("passwords with a length lower than 4 will never meet the security requirements")
ErrLengthTooLow represents an error thrown if the password will never be able match the security considerations in this package
var ErrPasswordInBreach = errors.New("given password is known to HaveIBeenPwned")
ErrPasswordInBreach signals the password passed was found in any breach at least once. The password should not be used if this error is returned.
Functions ¶
func CheckHIBPPasswordHash ¶
CheckHIBPPasswordHash accesses the HaveIBeenPwned API with the first 5 characters of the SHA1 hash of the password and scans the result for the password hash. If the hash is found the ErrPasswordInBreach error is thrown. In case of an HTTP error another error is thrown. The result will be nil when the password hash was not returned in the API output.
See more details at https://haveibeenpwned.com/API/v2#PwnedPasswords
Types ¶
type SecurePassword ¶
type SecurePassword struct {
// contains filtered or unexported fields
}
SecurePassword provides methods for generating secure passwords and checking the security requirements of passwords
func NewSecurePassword ¶
func NewSecurePassword() *SecurePassword
NewSecurePassword initializes a new SecurePassword generator
func (*SecurePassword) CheckPasswordSecurity ¶
func (s *SecurePassword) CheckPasswordSecurity(password string, needsSpecialCharacters bool) bool
CheckPasswordSecurity executes three checks to ensure the passwords meet the security considerations in this package:
1. The password may not contain pattern found on the keyboard or in alphabet 2. The password must have 3 or 4 different character groups in it 3. The password may not have repeating characters
func (*SecurePassword) GeneratePassword ¶
func (s *SecurePassword) GeneratePassword(length int, special bool) (string, error)
GeneratePassword generates a new password with a given length and optional special characters in it. The password is automatically checked against CheckPasswordSecurity in order to only deliver secure passwords.
type XKCD ¶
type XKCD struct { // Separator to be used between words Separator string }
XKCD represents a XKCD-style password generator
func NewXKCDGenerator ¶
func NewXKCDGenerator() *XKCD
NewXKCDGenerator initializes a new XKCD password generator https://xkcd.com/936/