Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/bcrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ var randomFallback = null;
* Generates cryptographically secure random bytes.
* @function
* @param {number} len Bytes length
* @param {boolean} testParam To avoid the warning if it is a test
* @returns {!Array.<number>} Random bytes
* @throws {Error} If no random implementation is available
* @inner
*/
function random(len) {
function random(len, testParam) {
/* fallback */
var test = testParam || false;
if (!randomFallback) {
console.warn("Using Math.random is not cryptographically secure! Use bcrypt.setRandomFallback to set a PRNG.");
if (!test) console.warn("Using Math.random is not cryptographically secure! Use bcrypt.setRandomFallback to set a PRNG.");
var buf = new Uint8Array(len);
return buf.map((item) => Math.floor(Math.random() * (256 - 1 + 1) + 1));
}
Expand All @@ -32,7 +34,7 @@ function random(len) {
// Test if any secure randomness source is available
var randomAvailable = false;
try {
random(1);
random(1, true);
randomAvailable = true;
} catch (e) {}

Expand Down