Skip to content

Allow User.hashPassword/validatePassword to be overridden - #941

Merged
raymondfeng merged 2 commits into
masterfrom
feature/workaround-issue-251
Jan 7, 2015
Merged

raymondfeng merged 2 commits into
masterfrom
feature/workaround-issue-251

Conversation

@raymondfeng

Copy link
Copy Markdown
Member

/to @ritch @bajtos

The PR allows User.hashPassword and validatePassword methods to be overridden. It can be used as a workaround to #251.

@bajtos

bajtos commented Jan 5, 2015

Copy link
Copy Markdown
Member

What is the scenario where users should override User.hashPassword? I am concerned that most developers don't understand security implications of different hashing algorithms and thus can easily introduce a serious vulnerability.

Comment thread common/models/user.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How throw new Error going to integrate with the existing validations? The request setting invalid password should return HTTP status 422 and a description of the validation error in the usual format. This code will IMO return 500 without enough details.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added statusCode.

@raymondfeng

Copy link
Copy Markdown
Member Author

The idea is allow functions to be customized for built-in models as app developers often have specific logic for the user model. Whoever decides to override the default behavior should already know what they are doing.

@bajtos

bajtos commented Jan 7, 2015

Copy link
Copy Markdown
Member

LGTM.

@bajtos

bajtos commented Jan 7, 2015

Copy link
Copy Markdown
Member

please check why the CI builds are failing before you land this patch.

@raymondfeng
raymondfeng force-pushed the feature/workaround-issue-251 branch from e78ce81 to 4a9c5b6 Compare January 7, 2015 21:57
raymondfeng added a commit that referenced this pull request Jan 7, 2015
Allow User.hashPassword/validatePassword to be overridden
@raymondfeng
raymondfeng merged commit 90fd62e into master Jan 7, 2015
@cleas

cleas commented May 1, 2015

Copy link
Copy Markdown

User.create({...}, function (err,user){...} ) will cause an uncaught exception as
validatePassword throws an error if the supplied password is invalid. This is a change in behavior , I would expect the error to be returned in the callback function.

@raymondfeng

Copy link
Copy Markdown
Member Author

Using the setter to hash passwords is pretty evil. We should find a better solution. Maybe the validatePassword should be set up as a validator on the User model.

@bajtos

bajtos commented May 4, 2015

Copy link
Copy Markdown
Member

Once we have "persist" hook in place (loopbackio/loopback-datasource-juggler#559), it should be very easy to rework the User model to hash the password in this hook.

Let's keep the scope of this discussion around the change in behaviour introduced by this pull request. @cleas can you post an example that works in loopback@2.8 and fails in loopback@2.9?

@cleas

cleas commented May 5, 2015

Copy link
Copy Markdown

@bajtos

bajtos commented May 5, 2015

Copy link
Copy Markdown
Member

@cleas can you please open a new github issue to track this problem? I'll post some ideas how to fix it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants