Documentation
¶
Index ¶
- Variables
- func CryptoRandom() int
- func Generate(length, minDigitLength, minSymbolLength, minUpperLetter uint) (string, error)
- func MathRandom() int
- func MustGenerate(length, minDigitLength, minSymbolLength, minUpperLetter uint) string
- type Argon2Params
- type Config
- type Generator
- type Hasher
- type HasherOption
- type PasswordInfo
- type RandomFunc
- type Validator
- type ValidatorOption
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrExceedsLength = errors.New("number of digits, symbols and upper letters must be less than total length")
Functions ¶
func Generate ¶ added in v1.1.0
Generate generates password via default config:
LowerLetters: abcdefghijklmnopqrstuvwxyz UpperLetters: ABCDEFGHIJKLMNOPQRSTUVWXYZ Digits: 0123456789 Symbols: ~!@#$%^&*()_+`-={}|[]\\:\"<>?,./
func MustGenerate ¶ added in v1.1.0
Generate generates password via default config, panic when error occcurred:
LowerLetters: abcdefghijklmnopqrstuvwxyz UpperLetters: ABCDEFGHIJKLMNOPQRSTUVWXYZ Digits: 0123456789 Symbols: ~!@#$%^&*()_+`-={}|[]\\:\"<>?,./
Types ¶
type Argon2Params ¶
type Argon2Params struct {
// contains filtered or unexported fields
}
Argon2Params Argon2id parameters
type Generator ¶ added in v1.1.0
type Generator interface { Generate(length, minDigitLength, minSymbolLength, minUpperLetter uint) (string, error) // MustGenerate like `Generate`, generates password. // // panic if errors occurred MustGenerate(length, minDigitLength, minSymbolLength, minUpperLetter uint) string }
Generator provides methods which generates password.
all methods are goroutine-safe.
func NewGenerator ¶ added in v1.1.0
type Hasher ¶
type Hasher interface { Encode(password string) (string, error) Decode(decoded string) (*PasswordInfo, error) Verify(password, encoded string) bool MustUpdate(encoded string) bool Harden(password, encoded string) (string, error) }
func NewHasher ¶
func NewHasher(opt *HasherOption) (Hasher, error)
type HasherOption ¶
type HasherOption struct { // Algorithm: Support md5, unsalted_md5, pbkdf2_sha256, pbkdf2_sha1, // argon2id, bcrypt, bcrypt_sha256, scrypt, sha1 Algorithm string `json:"algorithm"` Secret string `json:"secret"` // Salt: cannot contain '$' Salt string `json:"salt"` // Iterations: should be gratter than 0 Iterations int `json:"iterations"` Params interface{} `json:"params"` }
HasherOption Hasher option
func (*HasherOption) NewHasher ¶
func (ho *HasherOption) NewHasher() (Hasher, error)
type PasswordInfo ¶
type RandomFunc ¶ added in v1.1.0
type RandomFunc func() int
type Validator ¶
Validator for validating password
func NewValidator ¶
func NewValidator(opt *ValidatorOption) (Validator, error)
NewValidator return a Validator
type ValidatorOption ¶
type ValidatorOption struct { // MinLength should be more than 0, and less than `MaxLength` MinLength uint8 `json:"min_length"` // MaxLength should be less than 32, and more than `MinLength` MaxLength uint8 `json:"max_length"` CommonPasswordURL string `json:"common_password_url"` CommonPasswords []string `json:"common_passwords"` RequireDigit bool `json:"require_digit"` RequireLowercase bool `json:"require_lowercase"` RequireUppercase bool `json:"require_uppercase"` RequireLetter bool `json:"require_letter"` RequirePunctuation bool `json:"require_punctuation"` }
Validator option
Click to show internal directories.
Click to hide internal directories.