From 62b571e558e4f2f80e013e4ee4a2bd8d93991373 Mon Sep 17 00:00:00 2001 From: Naveen Mahalingam Date: Thu, 18 Apr 2024 11:50:17 -0700 Subject: [PATCH] minor comments --- password/generator.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/password/generator.go b/password/generator.go index ea2bf86..4fdfbef 100644 --- a/password/generator.go +++ b/password/generator.go @@ -67,6 +67,7 @@ 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-- { @@ -74,6 +75,8 @@ func (g *generator) Generate() string { idx++ } } + + // fill it with minimum requirements first if g.minLowerCase > 0 { fillPassword(g.charsetCaseLower, g.minLowerCase) } @@ -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) }