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/auth.js

45 lines
1.0 KiB
JavaScript

'use strict';
var db = require('../database'),
meta = require('../meta');
module.exports = function(User) {
User.auth = {};
User.auth.logAttempt = function(uid, callback) {
db.exists('lockout:' + uid, function(err, exists) {
if (err) {
return callback(err);
}
if (exists) {
return callback(new Error('[[error:account-locked]]'));
}
db.increment('loginAttempts:' + uid, function(err, attempts) {
if (err) {
return callback(err);
}
if ((meta.config.loginAttempts || 5) < attempts) {
// Lock out the account
db.set('lockout:' + uid, '', function(err) {
if (err) {
return callback(err);
}
db.delete('loginAttempts:' + uid);
db.pexpire('lockout:' + uid, 1000 * 60 * (meta.config.lockoutDuration || 60));
callback(new Error('account-locked'));
});
} else {
db.pexpire('loginAttempts:' + uid, 1000 * 60 * 60);
callback();
}
});
});
};
User.auth.clearLoginAttempts = function(uid) {
db.delete('loginAttempts:' + uid);
};
};