Skip to content

Instantly share code, notes, and snippets.

@newbyca
Created June 17, 2012 03:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save newbyca/2943281 to your computer and use it in GitHub Desktop.
Save newbyca/2943281 to your computer and use it in GitHub Desktop.
a password class i'm using in my nodejs project. i decided this abstraction was appropriate given a desire to create password hashs asyncly.
bcrypt = require 'bcrypt'
class password
text = null
salt = null
hash = null
@saltAndHash = (text, done) ->
bcrypt.genSalt (err, salt) ->
if err
return done err
password.hash text, salt, (err, pwd) ->
return done err, pwd
@hash = (text, salt, done) ->
pwd = new password
pwd.text = text
pwd.salt = salt
bcrypt.hash text, salt, (err, hash) ->
if err
return done err
pwd.hash = hash
return done null, pwd
module.exports = password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment