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

34 lines
796 B
JavaScript

'use strict';
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) {
db.getObjectField('user:' + uid, 'password', function(err, hashedPassword) {
if (err || !hashedPassword) {
return callback(err);
}
Password.compare(password || '', hashedPassword, callback);
});
};
User.hasPassword = function(uid, callback) {
db.getObjectField('user:' + uid, 'password', function(err, hashedPassword) {
callback(err, !!hashedPassword);
});
};
};