
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
mongoose-account-locking
Advanced tools
This mongoose plugin is based on the post by Jeremy Martin’s DevSmash Blog
npm install mongoose-account-locking
After define your Mongoose user schema, just add mongoose-account-locking as plugin to your user schema
UserSchema.plugin(locking);
You can also pass options when adding plugin
var options = {
, maxLoginAttempts = 5
, lockTime = 2 * 60 * 60 * 1000
, username = 'username'
, password = 'password';
};
User.plugin(locking, options)
where
maxLoginAttempts : Maximum number of allowable failed logins
lockTime : Amount of duration that account will be locked after exceeding the maxLoginAttemts
username : username key that is used in User schema. By default, it is 'username'. If you are using email as username, you can set to 'email'
password : password key that is used in User schema. By default, it is 'password'.
You can authenticate user as follows
// Create Model based on User Schema
var User = mongoose.model('User', UserSchema);
// Authenticate username and password
// If success, callback receive user
// If failure, callback receive err or reason
// Reasons are NOT_FOUND, PASSWORD_INCORRECT, and MAX_ATTEMPTS.
User.getAuthenticated('username', 'MyPassword', function(err, user, reason) {
// Write your code here
}
Refer examples folder for sample code
To verify the code, you have to run the sample.js 5 times. After 5th time, it will lock the account. It wont allow you to access the account for next 2 hours.
MIT License
FAQs
Account Locking for mongoose user schema
We found that mongoose-account-locking demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.