File tree 1 file changed +20
-2
lines changed
1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
+ "bytes"
5
+ r "crypto/rand"
6
+ "encoding/binary"
4
7
"fmt"
5
8
"math/rand"
6
9
"os"
7
10
"os/exec"
8
11
"runtime"
9
- "time"
10
12
)
11
13
12
14
// version history
13
15
// v0.1.0, 2023-01-10; initial release
14
16
// v0.1.1, 2023-01-11; added sanity checks to passwordLength & passwordCount inputs
17
+ // v0.1.2, 2023-02-09; use "crypto/rand" to create password seed
15
18
16
19
// clear screen function
17
20
func clearScreen () {
@@ -31,13 +34,28 @@ func clearScreen() {
31
34
}
32
35
}
33
36
37
+ func generateSeedKey () int64 {
38
+ b := make ([]byte , 16 )
39
+ _ , err := r .Read (b )
40
+ if err != nil {
41
+ fmt .Println ("Error:" , err )
42
+ return 0
43
+ }
44
+
45
+ var seed int64
46
+ binary .Read (bytes .NewReader (b ), binary .BigEndian , & seed )
47
+ return seed
48
+ }
49
+
34
50
func RandPassGen (n int ) string {
35
51
var alphaChars = []rune ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" )
36
52
var digitChars = []rune ("0123456789" )
37
53
var specialChars = []rune ("!@#$%^&*()_+-=[]{}\\ |;':\" <>,.?/" )
38
- rand . Seed ( time . Now (). UnixNano ())
54
+
39
55
b := make ([]rune , n )
40
56
for i := range b {
57
+ seed := generateSeedKey ()
58
+ rand .Seed (seed )
41
59
r := rand .Intn (3 )
42
60
if r == 0 {
43
61
b [i ] = alphaChars [rand .Intn (len (alphaChars ))]
You can’t perform that action at this time.
0 commit comments