🌜
🌞
passport-local

passport-local

v1.0.0

Local username and password authentication strategy for Passport.

npm install passport-local

README

passport-local

Build Coverage Quality Dependencies Tips

Passport strategy for authenticating with a username and password.

This module lets you authenticate using a username and password in your Node.js applications. By plugging into Passport, local authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

Install

$ npm install passport-local

Usage

Configure Strategy

The local authentication strategy authenticates users using a username and password. The strategy requires a verify callback, which accepts these credentials and calls done providing a user.

passport.use(new LocalStrategy(
  function(username, password, done) {
    User.findOne({ username: username }, function (err, user) {
      if (err) { return done(err); }
      if (!user) { return done(null, false); }
      if (!user.verifyPassword(password)) { return done(null, false); }
      return done(null, user);
    });
  }
));

Authenticate Requests

Use passport.authenticate(), specifying the 'local' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.post('/login', 
  passport.authenticate('local', { failureRedirect: '/login' }),
  function(req, res) {
    res.redirect('/');
  });

Examples

For complete, working examples, refer to the multiple examples included.

Tests

$ npm install
$ npm test

Credits

License

The MIT License

Copyright (c) 2011-2014 Jared Hanson <http://jaredhanson.net/>

General

License
MIT
Typescript Types
Tree-shakeable
No

Popularity

GitHub Stargazers
2,627
Community Interest
3,230
Number of Forks
519

Maintenance

Commits
11/2110/2201
Last Commit
Jun 29, 2021
Open Issues
46
Closed Issues
85
Open Pull Requests
11
Closed Pull Requests
31

Versions

Versions Released
11/2110/2201
Latest Version Released
Mar 8, 2014
Current Tags
latest1.0.0

Dependencies

Dependencies (1)
Dev Dependencies (3)

Contributors

jaredhanson
jaredhanson
Commits: 68
andr3w321
andr3w321
Commits: 8
bobzoller
bobzoller
Commits: 2
mhuggins
mhuggins
Commits: 1
pdehaan
pdehaan
Commits: 1
TechplexEngineer
TechplexEngineer
Commits: 1
fmalk
fmalk
Commits: 1
JayKan
JayKan
Commits: 1
nicrizzo
nicrizzo
Commits: 1
elmakras
elmakras
Commits: 1
atupal
atupal
Commits: 1
hemslo
hemslo
Commits: 1