Skip to content

Commit bc16601

Browse files
authored
Merge pull request #313 from dhensby/pulls/perf-improvement
perf: random tokens do not need to be hashed
2 parents 88c61c0 + 605c963 commit bc16601

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/utils/token-util.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
const randomBytes = require('crypto').randomBytes;
8-
const { createHash } = require('../utils/crypto-util');
98

109
/**
1110
* Export `TokenUtil`.
@@ -17,8 +16,15 @@ module.exports = {
1716
* Generate random token.
1817
*/
1918

20-
generateRandomToken: async function() {
21-
const buffer = randomBytes(256);
22-
return createHash({ data: buffer, encoding: 'hex' });
19+
generateRandomToken: function() {
20+
return new Promise((resolve, reject) => {
21+
randomBytes(32, (err, data) => {
22+
if (err) {
23+
reject(err);
24+
} else {
25+
resolve(data.toString('hex'));
26+
}
27+
});
28+
});
2329
}
2430
};

0 commit comments

Comments
 (0)