char mins done; need to shuffle some error condition checks before

This commit is contained in:
2022-03-04 01:04:14 -05:00
parent 77d5271b5a
commit 1c0481824e
9 changed files with 215 additions and 16 deletions
+25
View File
@@ -3,10 +3,16 @@ package pwgenerator
import (
"crypto/rand"
"math/big"
insecureRand "math/rand"
"sort"
"strings"
)
// newCryptoShuffler returns a new cryptoShuffler.
func newCryptoShuffler() *cryptoShuffler {
return new(cryptoShuffler)
}
/*
GetCharset returns a CharSet from a set of characters.
@@ -86,3 +92,22 @@ func saferRandInt(max int) (randInt int, err error) {
return
}
// passwordShuffle shuffles a password's characters ordering so we don't have the condition satisfiers in the beginning.
func passwordShuffle(passwd *string) {
var r *insecureRand.Rand = insecureRand.New(newCryptoShuffler())
r.Shuffle(
len(*passwd),
func(i, j int) {
var chars []rune = []rune(*passwd)
chars[i], chars[j] = chars[j], chars[i]
*passwd = string(chars)
},
)
return
}