Created
April 12, 2021 09:36
-
-
Save cunneen/6e29553fecb9487bc93aff8e4b5ee00d to your computer and use it in GitHub Desktop.
Meteor Password Hashing
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
// Based on https://forums.meteor.com/t/accounts-password-in-nodejs/45154 | |
const prompts = require('prompts'); | |
const hashPassword = require('./meteorpass') | |
let pass; | |
prompts([{ | |
type: 'password', | |
name: 'password', | |
message: 'Enter plaintext password', | |
}, | |
{ | |
type: 'password', | |
name: 'confirmPass', | |
message: (prev, values) => { pass = prev; return 'Confirm password' }, | |
validate: confirm => { | |
return (confirm === pass) ? true : 'Passwords don\'t match' ; | |
} | |
}]).then((response) => { | |
console.log(hashPassword(response.password)); | |
}) |
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
// Based on https://forums.meteor.com/t/accounts-password-in-nodejs/45154 | |
const bcrypt = require('bcrypt') | |
const hashPassword = (password) => { | |
const saltRounds = 10 | |
const salt = bcrypt.genSaltSync(saltRounds, 'a') | |
const hash = bcrypt.hashSync(password, salt) | |
return hash | |
} | |
module.exports = hashPassword; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Example: