Created
October 22, 2016 15:20
-
-
Save joynal/aaf78a12e72da7b6fa3b12008a5825a1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'use strict'; | |
const bcrypt = require('bcrypt'); | |
const crypto = require('crypto'); | |
function createNewUser(db, data){ | |
let user = db.createUser({ | |
name: data.name, | |
email: data.email, | |
password: makeHash(data.password), | |
}); | |
if(user) return sanitizeUserData(user); | |
return false; | |
} | |
function makeHash(key, salt_length = 10){ | |
return bcrypt.genSalt(salt_length, function(err, salt) { | |
return bcrypt.hash(key, salt, function(err, hash) { | |
return hash; | |
}); | |
}); | |
} | |
function sanitizeUserData(user) { | |
return user; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using sync
At Async return wont work. you have to use callback or promise
For nested callbacks use bluebird promise.