npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mongoose-account-locking

v0.0.1

Published

Account Locking for mongoose user schema

Readme

Mongoose Account Locking - Useful for Mongoose User Schema with locking

This mongoose plugin is based on the post by Jeremy Martin’s DevSmash Blog

How it works?

  • A user’s account should be “locked” after some number of consecutive failed login attempts
  • A user’s account should become unlocked once a sufficient amount of time has passed
  • The User model should expose the reason for a failed login attempt to the application (though not necessarily to the end user)

Installation

npm install mongoose-account-locking

How to use?

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
}

Example

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.

Contributors

License

MIT License