passport-local
    Overview
    Documentation
    Insights
    Code
    Contributors
    Dependencies
    Alternatives

passport-local

Local username and password authentication strategy for Passport.

1.0.0  •  Published 6 years ago  •  by Jared Hanson  •  Unknown License

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 © 2011-2014 Jared Hanson <http://jaredhanson.net/>

How do you feel about the name Devstore for this site?

Popularity

Weekly Downloads
261.9K
Stars
2.2K

Maintenance

Development

Last ver 6 years ago
Created 8 years ago
Last commit 6 months ago
1 month between commits

Technology

Node version: null
0 unpacked

Compliance

License Unknown
Not OSI Approved
0 vulnerabilities

Contributors

16 contributors
Jared Hanson
Maintainer, 82 commits, 19 merges
Andrew Rennhack
9 commits, 5 PRs
Kevin Coughlin
4 commits
Bob Zoller
2 commits, 1 PRs
Matt Huggins
1 commits, 1 PRs
Works at tanium
Blake Bourque
1 commits, 1 PRs
Works at Techplex Labs

Tags

passport
local
auth
authn
authentication
username
password
Ready for the next level?
Join Devstore's founding team to help us build the ultimate open-source app store, work with the latest technologies, and enjoy great culture, impact and autonomy
© 2019 Devstore, Inc.
Devstore helps developers find and use open-source packages, so they can focus on building amazing things