You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/src/user/password.js

45 lines
1.0 KiB
JavaScript

'use strict';
var async = require('async');
var nconf = require('nconf');
var db = require('../database');
var Password = require('../password');
module.exports = function (User) {
User.hashPassword = function (password, callback) {
if (!password) {
return callback(null, password);
}
Password.hash(nconf.get('bcrypt_rounds') || 12, password, callback);
};
User.isPasswordCorrect = function (uid, password, callback) {
password = password || '';
var hashedPassword;
async.waterfall([
function (next) {
db.getObjectField('user:' + uid, 'password', next);
},
function (_hashedPassword, next) {
hashedPassword = _hashedPassword;
if (!hashedPassword) {
return callback(null, true);
}
User.isPasswordValid(password, next);
},
function (next) {
Password.compare(password, hashedPassword, next);
},
], callback);
};
User.hasPassword = function (uid, callback) {
db.getObjectField('user:' + uid, 'password', function (err, hashedPassword) {
callback(err, !!hashedPassword);
});
};
};