passport.js with node.js to do Local Authentication

The whole example could be found in:

https://github.com/emacslisp/angular2/tree/meteor/passport-local

prerequisites

1. create an empty folder for project, say ‘passport-local’

1
2
3
4
5
6
7
npm init
npm install passport --save
npm install passport-local --save
npm install jade --save
npm install mongodb --save
npm install mongoose --save
npm install passport-local-mongoose --save

2. install mongodb and run
$ mongod

3. create an app.js

1
2
3
4
5
6
7
 
var path = require('path');
var express = require('express');
var http = require('http');
var mongoose = require('mongoose');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;

for more details check github project.

4. ‘node app’ to run the example

5. register user firstly, you will see ‘Account’ doc has been created with username, password and salt.

6. try to login to get session.