Created
April 15, 2017 00:19
-
-
Save oieduardorabelo/17741368f3cba8872fcc64917cc77aac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bcrypt = require('bcrypt'); | |
const NUM_SALT_ROUNDS = 8; | |
test(); | |
async function test() { | |
const pws = ['password', 'password1', 'passw0rd']; | |
// `promises` é uma array de Promises, porque `bcrypt.hash()` | |
// retorna uma promise se nenhum callback for passado | |
const promises = pws.map(pw => bcrypt.hash(pw, NUM_SALT_ROUNDS)); | |
/** | |
* Printa as senhas hasheadas, exemplo: | |
* [ '$2a$08$nUmCaLsQ9rUaGHIiQgFpAOkE2QPrn1Pyx02s4s8HC2zlh7E.o9wxC', | |
* '$2a$08$wdktZmCtsGrorU1mFWvJIOx3A0fbT7yJktRsRfNXa9HLGHOZ8GRjS', | |
* '$2a$08$VCdMy8NSwC8r9ip8eKI1QuBd9wSxPnZoZBw8b1QskK77tL2gxrUk.' ] | |
*/ | |
console.log(await Promise.all(promises)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment