mirror of
https://github.com/S2-/securerandomstring.git
synced 2025-08-02 18:30:04 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
bed8113750 | |||
a23c85cabe | |||
af5b2eaced | |||
51274ca17b | |||
f7e565bcc7 | |||
f82de05f4b |
@@ -31,6 +31,9 @@ function srs(options, cb) {
|
|||||||
} else {
|
} else {
|
||||||
string = string.replace(/\//g, '_').replace(/\+/g, '-');
|
string = string.replace(/\//g, '_').replace(/\+/g, '-');
|
||||||
}
|
}
|
||||||
|
if (string.length < length) {
|
||||||
|
return _finish(crypto.randomBytes(length));
|
||||||
|
}
|
||||||
return string.substr(0, length);
|
return string.substr(0, length);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "secure-random-string",
|
"name": "secure-random-string",
|
||||||
"version": "1.1.2",
|
"version": "1.1.4",
|
||||||
"description": "Generates a secure random string with a given length",
|
"description": "Generates a secure random string with a given length",
|
||||||
"main": "lib/secure-random-string.js",
|
"main": "lib/secure-random-string.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/S2-/securerandomstring.git"
|
"url": "https://github.com/5im-0n/securerandomstring.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"crypto",
|
"crypto",
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/S2-/securerandomstring/issues"
|
"url": "https://github.com/5im-0n/securerandomstring/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/S2-/securerandomstring"
|
"homepage": "https://github.com/5im-0n/securerandomstring"
|
||||||
}
|
}
|
||||||
|
1
tests.js
1
tests.js
@@ -68,6 +68,7 @@ srs({alphanumeric: true, length: 40}, function(err, sr) {;
|
|||||||
test('generate a random string 32 chars long (sync)', srs().length, 32);
|
test('generate a random string 32 chars long (sync)', srs().length, 32);
|
||||||
test('generate a random string 1 chars long (sync)', srs({length: 1}).length, 1);
|
test('generate a random string 1 chars long (sync)', srs({length: 1}).length, 1);
|
||||||
test('generate a random string 256 chars long (sync)', srs({length: 256}).length, 256);
|
test('generate a random string 256 chars long (sync)', srs({length: 256}).length, 256);
|
||||||
|
test('generate a random string 10 chars long (sync)', srs({length: 10}).length, 10);
|
||||||
|
|
||||||
|
|
||||||
//in 2000 chars there should be at least one substitution
|
//in 2000 chars there should be at least one substitution
|
||||||
|
Reference in New Issue
Block a user