Skip to content

Commit

Permalink
Merge pull request #63 from micaksica2/master
Browse files Browse the repository at this point in the history
Make randomDigits use crypto.randomBytes
  • Loading branch information
eddyystop authored Aug 6, 2017
2 parents efa4d80 + 19cfc32 commit 1aafcac
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ const randomBytes = len => new Promise((resolve, reject) => {
});

const randomDigits = len => {
const str = Math.random().toString() + Array(len + 1).join('0');
return str.substr(2, len);
let str = '';

while (str.length < len) {
str += parseInt('0x' + crypto.randomBytes(4).toString('hex')).toString();
}

return str.substr(0, len);
};

const getLongToken = len => randomBytes(len);
Expand Down

0 comments on commit 1aafcac

Please sign in to comment.