•  


GitHub - jaredhanson/passport-local: Username and password authentication strategy for Passport and Node.js.
Skip to content

jaredhanson/passport-local

Repository files navigation

passport-local

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 ? :dart: How-to ? :hammer_and_wrench: API Reference ? :heart: Sponsors


Advertisement
1Password, the only password manager you should trust. Industry-leading security and award winning design.


npm build coverage ...

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
)
;

    }
)
;

  }

)
)
;
Available Options

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.

Parameters

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
    // ...
  }
));

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

Additional examples can be found on the wiki .

License

The MIT License

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

- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본