venables / bookshelf-secure-password Goto Github PK
View Code? Open in Web Editor NEWA Bookshelf.js plugin for handling secure passwords
License: MIT License
A Bookshelf.js plugin for handling secure passwords
License: MIT License
I'm trying to use this plugin, but it's throwing PasswordMismatchError
errors when I try to use it with test data.
Here is my login code. I'm testing with username = "[email protected]"
, password = "password"
, and usernameField = "email"
. And I've confirmed (with console.log
) that these values are correct and that a user is being resolved by fetch
.
return Model.forge({ [usernameField]: username })
.fetch()
.then((user) => {
console.log({user, username, password, usernameField});
if(!user) return null;
return user.authenticate(password);
})
.catch((error) => {
console.log('login error', error);
return null;
});
Here is my seed file that creates the user with the credentials above:
exports.seed = async (knex) => {
const AdminUser = require('../lib/models/AdminUser');
await knex('admin_users').del();
await AdminUser.forge({
first_name: 'admin',
last_name: 'admin',
email: '[email protected]',
password: 'password',
}).save();
};
And here is the model definition for AdminUser
:
const AdminUser = app.model('AdminUser', {
tableName: 'admin_users',
hasSecurePassword: true,
hasTimestamps: ['createdAt', 'updatedAt'],
});
when I try to install bookshelf-secure-password I get an error, I saw that it couldn't find bcrypt, so i tried installing it first but it still failed because it's looking for it in the wrong directory (my_folder/node_modules/bookshelf-secure-password/node_modules/bcrypt)
so how do I change this, can I change it? how do I install it?
I have tried on windows and linux systems and tried wit different node versoins it still doesn't work (crappy library)
Running npm i
using NodeJs14 fails due to out of date bcrypt dependency.
Changing bcrypt version to 5.0.0 resolves the issue and appears to function as expected within my project however I've not tested extensively. It would be great to get this dependency bumped if possible!
Great module by the way ๐ .
The number of bcrypt rounds is hardcoded to 12 in this module. It would be nice to configure that.
I'm attempting to set the password database column as 'password' but there seems to be a problem specific to the string 'password'. When I attempt to save a model, the password is undefined. I can however change my column to anything other than 'password' and the plugin works as expected.
App info:
Typescript
knex 0.14.4
bookshelf 0.12.1
bookshelf-secure-password 3.0.1
Any help would be appreciated!
// userModel
import Database from '../db';
let db = Database.getInstance();
let bookshelf = db.getBookshelf();
export default class User extends bookshelf.Model<User> {
get tableName() { return 'users'; }
get hasTimestamps() { return true; }
get hasSecurePassword() { return 'password'; }
}
// userRouter
...
public put(req: Request, res: Response, next: NextFunction) {
new User(req.body)
.save()
.then((user) => {
res.status(200)
.send("'" + user.toJSON().username + "' was successfully created.");
})
.catch((err) => {
res.status(500)
.send(err);
});
}
...
// Error
{
"code": "EREQUEST",
"number": 515,
"lineNumber": 1,
"state": 2,
"class": 16,
"serverName": "xxxx",
"procName": "",
"originalError": {
"info": {
"number": 515,
"state": 2,
"class": 16,
"message": "Cannot insert the value NULL into column 'password', table 'API.dbo.users'; column does not allow nulls. INSERT fails.",
"serverName": "xxxx",
"procName": "",
"lineNumber": 1,
"name": "ERROR",
"event": "errorMessage"
}
},
"name": "RequestError",
"precedingErrors": []
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.