char mins done; need to shuffle some error condition checks before
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user