Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
bookshelf-secure-password
Advanced tools
Readme
A Bookshelf.js plugin for securely handling passwords.
password_digest
column in the database!yarn add bookshelf-secure-password
or
npm install bookshelf-secure-password --save
const bookshelf = require('bookshelf')(knex)
const securePassword = require('bookshelf-secure-password')
bookshelf.plugin(securePassword)
hasSecurePassword
to the model(s) which require a secure passwordconst User = bookshelf.Model.extend({
tableName: 'users',
hasSecurePassword: true
})
By default, this will use the database column named password_digest
. To use a different column, simply change true
to be the column name. For example:
const User = bookshelf.Model.extend({
tableName: 'users',
hasSecurePassword: 'custom_password_digest_field'
})
password_digest
:user = new User({ password: 'testing' })
user.get('password') // => undefined
user.get('password_digest') // => undefined
user.save().then(function () {
user.get('password') // => undefined
user.get('password_digest') // => '$2a$12$SzUDit15feMdVCtfSzopc.0LuqeHlJInqq/1Ol8uxCC5QydHpVWFy'
})
authenticate
, which returns a Promise
resolving to the authenticated Model.user.authenticate('some-password').then(function (user) {
// do something with the authenticated user
}, function (err) {
// invalid password.
// `err` will be of type `PasswordMismatchError`, which extends the `Error` class
})
const User = require('./models/User')
/**
* Sign up a new user.
*
* @returns {Promise.<User>} A promise resolving to the newly registered User, or rejected with an error.
*/
function signUp (email, password) {
let user = new User({ email: email, password: password })
return user.save()
}
/**
* Sign in with a given email, password combination
*
* @returns {Promise.<User>} A promise resolving to the authenticated User, or rejected with a `PasswordMismatchError`.
*/
function signIn (email, password) {
return User.forge({ email: email })
.fetch()
.then(function (user) {
return user.authenticate(password)
})
}
bookshelf-virtuals-plugin
plugin on Bookshelf for the virtual password
field.null
value to the password will clear the password_digest
.undefined
or a zero-length string to the password will leave the password_digest
as-isTo run the tests locally, simply run yarn test
or npm test
FAQs
A Bookshelf.js plugin for handling secure passwords
The npm package bookshelf-secure-password receives a total of 32 weekly downloads. As such, bookshelf-secure-password popularity was classified as not popular.
We found that bookshelf-secure-password demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.