mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
closes #4041
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
|
||||
"username-too-short": "Username too short",
|
||||
"username-too-long": "Username too long",
|
||||
"password-too-long": "Password too long",
|
||||
|
||||
"user-banned": "User banned",
|
||||
"user-too-new": "Sorry, you are required to wait %1 second(s) before making your first post",
|
||||
|
||||
@@ -216,25 +216,28 @@ function continueLogin(req, res, next) {
|
||||
}
|
||||
|
||||
authenticationController.localLogin = function(req, username, password, next) {
|
||||
if (!username || !password) {
|
||||
return next(new Error('[[error:invalid-password]]'));
|
||||
if (!username) {
|
||||
return next(new Error('[[error:invalid-username]]'));
|
||||
}
|
||||
|
||||
var userslug = utils.slugify(username);
|
||||
var uid, userData = {};
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
user.isPasswordValid(password, next);
|
||||
},
|
||||
function (next) {
|
||||
user.getUidByUserslug(userslug, next);
|
||||
},
|
||||
function(_uid, next) {
|
||||
function (_uid, next) {
|
||||
if (!_uid) {
|
||||
return next(new Error('[[error:no-user]]'));
|
||||
}
|
||||
uid = _uid;
|
||||
user.auth.logAttempt(uid, req.ip, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
async.parallel({
|
||||
userData: function(next) {
|
||||
db.getObjectFields('user:' + uid, ['password', 'banned', 'passwordExpiry'], next);
|
||||
@@ -244,7 +247,7 @@ authenticationController.localLogin = function(req, username, password, next) {
|
||||
}
|
||||
}, next);
|
||||
},
|
||||
function(result, next) {
|
||||
function (result, next) {
|
||||
userData = result.userData;
|
||||
userData.uid = uid;
|
||||
userData.isAdmin = result.isAdmin;
|
||||
@@ -261,7 +264,7 @@ authenticationController.localLogin = function(req, username, password, next) {
|
||||
}
|
||||
Password.compare(password, userData.password, next);
|
||||
},
|
||||
function(passwordMatch, next) {
|
||||
function (passwordMatch, next) {
|
||||
if (!passwordMatch) {
|
||||
return next(new Error('[[error:invalid-password]]'));
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ module.exports = function(SocketUser) {
|
||||
}
|
||||
|
||||
SocketUser.changePassword = function(socket, data, callback) {
|
||||
if (!data || !data.uid || data.newPassword.length < meta.config.minimumPasswordLength) {
|
||||
if (!data || !data.uid) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
if (!socket.uid) {
|
||||
|
||||
@@ -185,6 +185,11 @@ module.exports = function(User) {
|
||||
if (password.length < meta.config.minimumPasswordLength) {
|
||||
return callback(new Error('[[user:change_password_error_length]]'));
|
||||
}
|
||||
|
||||
if (password.length > 4096) {
|
||||
return callback(new Error('[[error:password-too-long]]'));
|
||||
}
|
||||
|
||||
callback();
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
|
||||
var db = require('../database');
|
||||
@@ -16,13 +17,21 @@ module.exports = function(User) {
|
||||
};
|
||||
|
||||
User.isPasswordCorrect = function(uid, password, callback) {
|
||||
db.getObjectField('user:' + uid, 'password', function(err, hashedPassword) {
|
||||
if (err || !hashedPassword) {
|
||||
return callback(err);
|
||||
password = password || '';
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
User.isPasswordValid(password, next);
|
||||
},
|
||||
function (next) {
|
||||
db.getObjectField('user:' + uid, 'password', next);
|
||||
},
|
||||
function (hashedPassword, next) {
|
||||
if (!hashedPassword) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
Password.compare(password || '', hashedPassword, callback);
|
||||
});
|
||||
Password.compare(password, hashedPassword, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
User.hasPassword = function(uid, callback) {
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
validator = require('validator'),
|
||||
url = require('url'),
|
||||
S = require('string'),
|
||||
var async = require('async');
|
||||
var S = require('string');
|
||||
|
||||
utils = require('../../public/src/utils'),
|
||||
meta = require('../meta'),
|
||||
events = require('../events'),
|
||||
db = require('../database'),
|
||||
Password = require('../password'),
|
||||
plugins = require('../plugins');
|
||||
var utils = require('../../public/src/utils');
|
||||
var meta = require('../meta');
|
||||
var db = require('../database');
|
||||
var plugins = require('../plugins');
|
||||
|
||||
module.exports = function(User) {
|
||||
|
||||
@@ -246,39 +242,32 @@ module.exports = function(User) {
|
||||
return callback(new Error('[[error:invalid-uid]]'));
|
||||
}
|
||||
|
||||
function hashAndSetPassword(callback) {
|
||||
User.hashPassword(data.newPassword, function(err, hash) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
async.parallel([
|
||||
async.apply(User.setUserField, data.uid, 'password', hash),
|
||||
async.apply(User.reset.updateExpiry, data.uid)
|
||||
], callback);
|
||||
});
|
||||
}
|
||||
|
||||
if (!utils.isPasswordValid(data.newPassword)) {
|
||||
return callback(new Error('[[user:change_password_error]]'));
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
User.isPasswordValid(data.newPassword, next);
|
||||
},
|
||||
function (next) {
|
||||
if (parseInt(uid, 10) !== parseInt(data.uid, 10)) {
|
||||
User.isAdministrator(uid, function(err, isAdmin) {
|
||||
if (err || !isAdmin) {
|
||||
return callback(err || new Error('[[user:change_password_error_privileges'));
|
||||
}
|
||||
|
||||
hashAndSetPassword(callback);
|
||||
});
|
||||
User.isAdministrator(uid, next);
|
||||
} else {
|
||||
User.isPasswordCorrect(uid, data.currentPassword, function(err, correct) {
|
||||
if (err || !correct) {
|
||||
return callback(err || new Error('[[user:change_password_error_wrong_current]]'));
|
||||
User.isPasswordCorrect(uid, data.currentPassword, next);
|
||||
}
|
||||
},
|
||||
function (isAdminOrPasswordMatch, next) {
|
||||
if (!isAdminOrPasswordMatch) {
|
||||
return next(new Error('[[error:change_password_error_wrong_current]]'));
|
||||
}
|
||||
|
||||
hashAndSetPassword(callback);
|
||||
User.hashPassword(data.newPassword, next);
|
||||
},
|
||||
function (hashedPassword, next) {
|
||||
async.parallel([
|
||||
async.apply(User.setUserField, data.uid, 'password', hashedPassword),
|
||||
async.apply(User.reset.updateExpiry, data.uid)
|
||||
], function(err) {
|
||||
next(err);
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user