args... still needs charset minimums (how?)

This commit is contained in:
2022-03-03 04:26:44 -05:00
parent 1cb6879786
commit 480dcd7e24
11 changed files with 254 additions and 2 deletions
+26
View File
@@ -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
}