Skip to content

Instantly share code, notes, and snippets.

@cunneen
Created April 12, 2021 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cunneen/6e29553fecb9487bc93aff8e4b5ee00d to your computer and use it in GitHub Desktop.
Save cunneen/6e29553fecb9487bc93aff8e4b5ee00d to your computer and use it in GitHub Desktop.
Meteor Password Hashing
// 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));
})
// 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;
@cunneen
Copy link
Author

cunneen commented Apr 12, 2021

Usage:

npm install bcrypt prompts
node getHashedPassword.js

Example:

% node getHashedPassword.js
✔ Enter plaintext password … *********
✔ Confirm password … *********
$2a$10$ovBWava0MVkz8gmc9RSqteMuZqoa/0pjZW3WfngTUU.TDySKHccPu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment