Documentation
¶
Overview ¶
Package passgen generates deterministic passwords from a passphrase and salt. The same passphrase + salt + options always produces the same password.
Example:
pass, err := passgen.New("mypassphrase").WithSalt("mysalt").WithLength(32).Generate()
if err != nil {
log.Fatal(err)
}
fmt.Println(pass)
Index ¶
- type Builder
- func (b *Builder) Generate() (string, error)
- func (b *Builder) NoAmbiguous() *Builder
- func (b *Builder) NoNumbers() *Builder
- func (b *Builder) NoSpecials() *Builder
- func (b *Builder) NoUppers() *Builder
- func (b *Builder) WithAmbiguousChars(chars string) *Builder
- func (b *Builder) WithLength(n int) *Builder
- func (b *Builder) WithSalt(salt string) *Builder
- func (b *Builder) WithSpecials(chars string) *Builder
- func (b *Builder) WithVersion(v int) *Builder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder constructs a deterministic password generation request. Use New to create a Builder with sensible defaults.
Builder methods return a new Builder (copy), so a base Builder can be reused safely without mutation:
base := passgen.New("mypassphrase").WithSalt("mysalt")
pass16, _ := base.WithLength(16).Generate()
pass32, _ := base.WithLength(32).Generate()
func New ¶
New returns a Builder for the given passphrase with defaults: v3 algorithm, length 40, all character classes enabled, specials = !@#$%^&*. No environment variables are read.
func (*Builder) Generate ¶
Generate produces a deterministic password from the passphrase provided to New.
Returns an error if:
- The passphrase is empty.
- The length is less than 1.
- The version is not 1, 2, or 3.
- All character classes are disabled (leaving no characters to sample from).
- (v2) The character set has fewer than 2 characters.
- (v2) A required character class is filtered away entirely (e.g. by ambiguous-character exclusion).
- (v2) The length is shorter than the number of required character classes.
- (v3) A character class is longer than 256 characters.
func (*Builder) NoAmbiguous ¶
NoAmbiguous excludes the default ambiguous characters (Il1O05S) from the generated password. Use [WithAmbiguousChars] to supply a custom set.
func (*Builder) NoSpecials ¶
NoSpecials disables special characters in the generated password entirely.
func (*Builder) WithAmbiguousChars ¶
WithAmbiguousChars sets a custom set of characters to exclude as visually ambiguous. Calling this implicitly enables ambiguous filtering. The default ambiguous set (used by [NoAmbiguous]) is "Il1O05S".
func (*Builder) WithLength ¶
WithLength sets the output password length. Must be at least 1. Default: 40.
func (*Builder) WithSalt ¶
WithSalt appends a salt to the passphrase before hashing. A unique salt makes passwords specific to a user or context.
func (*Builder) WithSpecials ¶
WithSpecials sets a custom special character set to use instead of the default (!@#$%^&*). Has no effect if [NoSpecials] has been called.
func (*Builder) WithVersion ¶
WithVersion selects the algorithm version. Valid values: 1, 2, 3. The default (0 or unset) maps to version 3.