Skip to content

candland/connect-forms-authentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a simple forms based authentication framework

Checkout connect-auth for a full featured option.

The goals of this is to allow you to hook into your own methods for authentication while providing some simplification of the process.

Required connect middleware

  • app.use(express.cookieDecoder());
  • app.use(express.session({secret: 'random-string'}));

Usage

These examples are using expressjs, but should work with just connectjs.

Require the library:

var auth = require('./node-forms-authentication');

Use this to handle your login post. Call callback with a user id if successful, undefined otherwise.

app.post('/login', auth.setAuthenticatedUser('/admin', function(req, callback) {
	callback(1);
});

Logout can be handled like this.

app.get('/logout', auth.removeAuthenticatedUser('/'));

Secure a page.

app.get('/admin', auth.authenticate, function(req, res) {
	res.send("admin page user id: " + req.session.userId);
});

Create a hashed password.

var hashed = auth.hashPassword('password', 'salt');

About

A simple forms authentication library for expressjs/connect

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published