Skip to content

Commit

Permalink
minor comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jedib0t committed Apr 18, 2024
1 parent 83c3198 commit 62b571e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions password/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ func (g *generator) Generate() string {
password := g.pool.Get().([]rune)
defer g.pool.Put(password)

// init the filler
idx := 0
fillPassword := func(runes []rune, count int) {
for ; idx < len(password) && count > 0; count-- {
password[idx] = runes[g.rng.IntN(len(runes))]
idx++
}
}

// fill it with minimum requirements first
if g.minLowerCase > 0 {
fillPassword(g.charsetCaseLower, g.minLowerCase)
}
Expand All @@ -83,6 +86,7 @@ func (g *generator) Generate() string {
if numSymbols := g.numSymbolsToGenerate(); numSymbols > 0 {
fillPassword(g.charsetSymbols, numSymbols)
}
// fill the rest with non-symbols (as symbols has a max)
if remainingChars := len(password) - idx; remainingChars > 0 {
fillPassword(g.charsetNonSymbols, remainingChars)
}
Expand Down

0 comments on commit 62b571e

Please sign in to comment.