args... still needs charset minimums (how?)
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package pwgenerator
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
"sort"
|
||||
)
|
||||
|
||||
@@ -31,3 +34,26 @@ func sortDedupe(charset *CharSet) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
saferRandInt uses crypto/rand instead of math/rand to get a random number.
|
||||
|
||||
While this is cryptographically safer, I guarantee it's a much bigger pain to do.
|
||||
*/
|
||||
func saferRandInt(max int) (randInt int, err error) {
|
||||
|
||||
var max64 int64 = int64(max)
|
||||
var cryptoInt *big.Int = big.NewInt(max64)
|
||||
var cryptoReader *bytes.Buffer = new(bytes.Buffer)
|
||||
var randInt64 int64
|
||||
|
||||
if cryptoInt, err = rand.Int(cryptoReader, cryptoInt); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
randInt64 = cryptoInt.Int64()
|
||||
|
||||
randInt = int(randInt64)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user