Skip to content

venables/bookshelf-secure-password

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

bookshelf-secure-password

Dependency Status

A Bookshelf.js plugin for handling secure passwords.

Adds a method to set and authenticate against a BCrypt password.

Similar to has_secure_password in Ruby on Rails.

Installation

npm install bookshelf-secure-password --save

Usage

  1. Initialize the plugin
...
var bookshelf = require('bookshelf')(knex);
var securePassword = require('bookshelf-secure-password');

bookshelf.plugin(securePassword);
  1. Add hasSecurePassword to the model(s) which require a secure password
var User = bookshelf.Model.extend({
  tableName: 'users',
  hasSecurePassword: true
});

By default, this requires a field on the table named password_digest. To use a different column, simply set true to be the column name. For example:

var User = bookshelf.Model.extend({
  tableName: 'users',
  hasSecurePassword: 'custom_password_digest_field'
});
  1. To authenticate against the password, simply call the instance method authenticate:
var authenticated = user.authenticate('some-password');

Notes

  • This library uses the sync methods for bcrypt. This is to ensure the raw password is never stored on the model.