-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow passwords to be all numbers #2335
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -604,8 +604,8 @@ module.exports = function(User) { | |
}; | ||
|
||
UserModel.setter.password = function(plain) { | ||
if (typeof plain !== 'string') { | ||
return; | ||
if (typeof plain === 'number') { | ||
plain = plain.toString(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that this check should be removed entirely. What if someone makes a mistake somewhere and This could also be cleaned up to one line: if (typeof plain !== 'string') return; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably better to take advantage of the if (typeof plain === 'string' && plain.indexOf('$2a$') === 0 && plain.length === 60) {
// ...
} else {
this.$password = this.constructor.hashPassword(plain);
} so if User.hashPassword = function(plain) {
this.validatePassword(plain);
// ...
};
User.validatePassword = function(plain) {
if (typeof plain === 'string' && plain) {
return true;
}
var err = new Error('Invalid password: ' + plain);
err.statusCode = 422;
throw err;
}; at which point it will throw a better error message What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @reichert621 I like it. But doesn't that still leave the loophole where all-number passwords are still not converted to strings? Your version will throw the error in that case, but I'm not sure it should be up to the framework to say if they should be allowed or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The enforcement of at least one non-numeric character is a bug as labelled in #2324. The hashing algorithm requires a string of characters but a number should be coerced to a string and that should be the outcome of this PR. I just want to be clear that the current behavior is not what is expected. @notbrain, looking forward to seeing the rest of your changes. |
||
if (plain.indexOf('$2a$') === 0 && plain.length === 60) { | ||
// The password is already hashed. It can be the case | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary but could be cleaned up to one line as suggested in my other comment.