Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Passport | 21,797 | 81,272 | 4,389 | 11 days ago | 32 | May 20, 2022 | 375 | mit | JavaScript | |
Simple, unobtrusive authentication for Node.js. | ||||||||||
Node Express Realworld Example App | 3,434 | 1 | 2 | 7 months ago | 1 | June 28, 2018 | 73 | JavaScript | ||
Passport Local | 2,637 | 54,881 | 2,067 | 9 months ago | 8 | March 08, 2014 | 57 | mit | JavaScript | |
Username and password authentication strategy for Passport and Node.js. | ||||||||||
Permit | 1,664 | 8 | 8 | a year ago | 8 | July 17, 2018 | 8 | mit | JavaScript | |
An unopinionated authentication library for building Node.js APIs. | ||||||||||
Nextjs Starter | 1,294 | 3 years ago | 34 | isc | JavaScript | |||||
A starter project for Next.js with authentication | ||||||||||
Passport Facebook | 1,277 | 20,701 | 573 | 5 months ago | 15 | January 22, 2019 | 126 | mit | JavaScript | |
Facebook authentication strategy for Passport and Node.js. | ||||||||||
Nextjs Mongodb App | 1,164 | a year ago | 16 | mit | JavaScript | |||||
A Next.js and MongoDB web application, designed with simplicity for learning and real-world applicability in mind. | ||||||||||
Passport Http Bearer | 938 | 4,428 | 549 | 10 months ago | 7 | August 02, 2013 | 17 | mit | JavaScript | |
HTTP Bearer authentication strategy for Passport and Node.js. | ||||||||||
Koa Passport | 773 | 1,056 | 149 | 8 months ago | 39 | March 11, 2021 | 10 | mit | JavaScript | |
Passport middleware for Koa | ||||||||||
Passport Google Oauth2 | 756 | 4,602 | 173 | 5 months ago | 2 | March 08, 2019 | 51 | mit | JavaScript | |
Google authentication strategy for Passport and Node.js. |
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, password-based sign in can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.
🌱 Tutorial • 🎯 How-to • 🛠 API Reference • ❤️ Sponsors
Advertisement
1Password, the only password manager you should trust. Industry-leading security and award winning design.
$ npm install passport-local
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);
});
}
));
This strategy takes an optional options hash before the function, e.g. new LocalStrategy({/* options */, callback})
.
The available options are:
usernameField
- Optional, defaults to 'username'passwordField
- Optional, defaults to 'password'Both fields define the name of the properties in the POST body that are sent to the server.
By default, LocalStrategy
expects to find credentials in parameters
named username and password. If your site prefers to name these fields
differently, options are available to change the defaults.
passport.use(new LocalStrategy({
usernameField: 'email',
passwordField: 'passwd',
session: false
},
function(username, password, done) {
// ...
}
));
When session support is not necessary, it can be safely disabled by
setting the session
option to false.
The verify callback can be supplied with the request
object by setting
the passReqToCallback
option to true, and changing callback arguments
accordingly.
passport.use(new LocalStrategy({
usernameField: 'email',
passwordField: 'passwd',
passReqToCallback: true,
session: false
},
function(req, username, password, done) {
// request object is now first argument
// ...
}
));
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('/');
});
Illustrates how to use the password strategy within an Express application.
Additional examples can be found on the wiki.
Copyright (c) 2011-2015 Jared Hanson <http://jaredhanson.net/>