- requireRegexValidation toggles whether or not password validation is controlled by regular expression - requireStrongPasswords toggles whether password validation is controlled by zxcvbn package LT-104: User account shall be locked after 5 failed attempts - "failedAttemptsLimit" property which is under passwordOptions in ActiveEntry configuration object sets number of failed attempts count to lock user account, it is set 5 as default LT-99: Passwords shall use password history of 6 - "passwordHistoryCount" property which is under passwordOptions in ActiveEntry configuration object sets count of last passwords that is not used to reset password - Show error messages in changePassword template - Make signIn button disabled if inputs are not validated
77 lines
2.9 KiB
JavaScript
77 lines
2.9 KiB
JavaScript
Meteor.methods({
|
|
initializeEntryUsers: function (){
|
|
console.log('Initializing Users', Meteor.users.find().fetch());
|
|
|
|
},
|
|
|
|
dropEntryUsers: function (){
|
|
console.log('Drop Users', Meteor.users.find().fetch());
|
|
Meteor.users.find().forEach(function(user){
|
|
Meteor.users.remove({_id: user._id});
|
|
});
|
|
},
|
|
|
|
insertHashedPassword: function(passwordParameters) {
|
|
var hashedPassword = passwordParameters[0];
|
|
var passwordHistoryCount = passwordParameters[1];
|
|
|
|
var userId = Meteor.userId();
|
|
var previousPasswords = Meteor.users.findOne({_id: userId}).previousPasswords;
|
|
if (previousPasswords) {
|
|
if (previousPasswords.length == passwordHistoryCount) {
|
|
// Remove oldest password
|
|
var ascSortedPasswords = _.sortBy(previousPasswords, function(previousPassword){ return previousPassword.createdAt; });
|
|
ascSortedPasswords.splice(0, 1);
|
|
previousPasswords = ascSortedPasswords;
|
|
}
|
|
|
|
previousPasswords.push({hashedPassword: hashedPassword, createdAt: new Date()});
|
|
Meteor.users.update({_id: userId}, {$set: {previousPasswords: previousPasswords}});
|
|
} else {
|
|
Meteor.users.update({_id: userId}, {$set: {previousPasswords: [{hashedPassword: hashedPassword, createdAt: new Date(), select: false}]}});
|
|
}
|
|
},
|
|
|
|
checkPasswordExistence: function(hashedPassword) {
|
|
var previousPasswords = Meteor.users.find({_id: Meteor.userId()}).fetch()[0].previousPasswords;
|
|
for(var i=0; i< previousPasswords.length; i++) {
|
|
var recordedHashedPassword = previousPasswords[i].hashedPassword;
|
|
if (recordedHashedPassword == hashedPassword) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
|
|
},
|
|
|
|
getFailedAttemptsCount: function(emailAddress) {
|
|
return Meteor.users.findOne({"emails.address": emailAddress}).failedPasswordAttempts || 0;
|
|
},
|
|
|
|
updateFailedAttempts: function(failedAttemptsParameters) {
|
|
var emailAddress = failedAttemptsParameters[0];
|
|
var failedAttemptsLimit = failedAttemptsParameters[1];
|
|
var failedAttemptCount = Meteor.users.findOne({"emails.address": emailAddress}).failedPasswordAttempts || 0;
|
|
if (failedAttemptCount == failedAttemptsLimit) {
|
|
return failedAttemptCount;
|
|
} else {
|
|
if (failedAttemptCount == 4) {
|
|
// Locked user account
|
|
Meteor.users.update({"emails.address": emailAddress}, {$set: {"profile.isLocked": true, failedPasswordAttempts: failedAttemptCount + 1}});
|
|
} else if (failedAttemptCount < 4) {
|
|
Meteor.users.update({"emails.address": emailAddress}, {$set: {failedPasswordAttempts: failedAttemptCount + 1}});
|
|
}
|
|
}
|
|
|
|
return failedAttemptCount + 1;
|
|
},
|
|
|
|
resetFailedAttempts: function(emailAddress) {
|
|
Meteor.users.update({"emails.address": emailAddress}, {$set: {failedPasswordAttempts: 0}});
|
|
},
|
|
|
|
updatePasswordCreatedDate: function() {
|
|
Meteor.users.update({_id: Meteor.userId()}, {$set: {"services.password.createdAt": new Date()}});
|
|
}
|
|
});
|