We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a1bc3f8 commit ef2d064Copy full SHA for ef2d064
index.js
@@ -1,5 +1,6 @@
1
2
var assert = require('assert')
3
+var crypto = require('crypto')
4
5
var base62 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
6
var base36 = 'abcdefghijklmnopqrstuvwxyz0123456789'
@@ -19,7 +20,10 @@ function create(chars) {
19
20
len = len || 10
21
assert(typeof len === 'number' && len >= 0, 'the length of the random string must be a number!')
22
var salt = ''
- for (var i = 0; i < len; i++) salt += chars[Math.floor(length * Math.random())]
23
+ for (var i = 0; i < len; i++) {
24
+ var rndVal = (crypto.randomBytes(1).readIntBE(0,1) + 128) / 256;
25
+ salt += chars[Math.floor(length * rndVal)]
26
+ }
27
return salt
28
}
29
0 commit comments