Skip to content

Commit

Permalink
Merge pull request #894 from lpizzinidev/patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
recrsn committed Oct 6, 2022
2 parents fc225b1 + 5283ad1 commit 0884c5b
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions examples/async_compare.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
var bcrypt = require('../bcrypt');

var start = Date.now();
bcrypt.genSalt(10, function(err, salt) {
console.log('salt: ' + salt);
console.log('salt cb end: ' + (Date.now() - start) + 'ms');
bcrypt.hash('test', salt, function(err, crypted) {
(async () => {
const start = Date.now();

// genSalt
const salt = await bcrypt.genSalt(10)
console.log('salt: ' + salt);
console.log('salt cb end: ' + (Date.now() - start) + 'ms');

// hash
const crypted = await bcrypt.hash('test', salt)
console.log('crypted: ' + crypted);
console.log('crypted cb end: ' + (Date.now() - start) + 'ms');
console.log('rounds used from hash:', bcrypt.getRounds(crypted));
bcrypt.compare('test', crypted, function(err, res) {
console.log('compared true: ' + res);
console.log('compared true cb end: ' + (Date.now() - start) + 'ms');
});
bcrypt.compare('bacon', crypted, function(err, res) {
console.log('compared false: ' + res);
console.log('compared false cb end: ' + (Date.now() - start) + 'ms');
});
});
})
console.log('end: ' + (Date.now() - start) + 'ms');

// compare
const res = await bcrypt.compare('test', crypted)
console.log('compared true: ' + res);
console.log('compared true cb end: ' + (Date.now() - start) + 'ms');

// compare
const res = await bcrypt.compare('bacon', crypted)
console.log('compared false: ' + res);
console.log('compared false cb end: ' + (Date.now() - start) + 'ms');

console.log('end: ' + (Date.now() - start) + 'ms');
})();

0 comments on commit 0884c5b

Please sign in to comment.