Repository navigation
Modified PATCH '/v1/account/phone' API to re-hash password - #5003
harshmange44 wants to merge 3 commits into
Conversation
…ult algo if it's anonymous user
|
Fixed #4990 |
stnguyen90
left a comment
There was a problem hiding this comment.
Great PR! 🤯 We left some comments during the review, please check them out.
| } | ||
|
|
||
| $user | ||
| ->setAttribute('password', $isAnonymousUser ? Auth::passwordHash($password, Auth::DEFAULT_ALGO, Auth::DEFAULT_ALGO_OPTIONS) : $user->getAttribute('password', '')) |
There was a problem hiding this comment.
Please also make sure to update the hash and hashOptions attributes.
| ->setAttribute('password', $isAnonymousUser ? Auth::passwordHash($password, Auth::DEFAULT_ALGO, Auth::DEFAULT_ALGO_OPTIONS) : $user->getAttribute('password', '')) | ||
| ->setAttribute('hash', $isAnonymousUser ? Auth::DEFAULT_ALGO : $user->getAttribute('hash', '')) | ||
| ->setAttribute('hashOptions', $isAnonymousUser ? Auth::DEFAULT_ALGO_OPTIONS : $user->getAttribute('hashOptions', '')) |
There was a problem hiding this comment.
@Meldiron is this logic right? Is it supposed to be !$isAnonymousUser?
There was a problem hiding this comment.
Honestly not sure why we ask for password in update phone endpoint. What password is expected in case of anonymous user? Why does "update phone" also update password? If anonymous user used this endpoint and entered password, do I understand correctly this would claim account for him not only by phone, but also by password?
If all of that is expected, then the logic makes sense. If anonymous, generate password hash. If anonymous, configure hash algo. If not, leave as it was.
There was a problem hiding this comment.
Honestly not sure why we ask for password in update phone endpoint.
Probably as an extra security measure. Same idea behind asking for password for update email. However, the user is less likely to have a password in this case...
Why does "update phone" also update password?
Probably because update email does. And I think the justification was we want to rehash as soon as we have the password to make sure it's hashed using the default algorithm
If anonymous user used this endpoint and entered password, do I understand correctly this would claim account for him not only by phone, but also by password?
What do you mean by claim? I think it would set the password, just like the update email API
If all of that is expected, then the logic makes sense. If anonymous, generate password hash. If anonymous, configure hash algo. If not, leave as it was.
I'd like to get your insight into what should happen since you were involved in adding this type of code to the update email endpoint.
There was a problem hiding this comment.
@stnguyen90 Any update, are we going to merge this one?
There was a problem hiding this comment.
Sorry, looks like we're going to change the behavior a bit.
- We don't want to update the password for users without a password
- We don't want to verify the password if the user doesn't have a password
| ->setAttribute('password', $isAnonymousUser ? Auth::passwordHash($password, Auth::DEFAULT_ALGO, Auth::DEFAULT_ALGO_OPTIONS) : $user->getAttribute('password', '')) | ||
| ->setAttribute('hash', $isAnonymousUser ? Auth::DEFAULT_ALGO : $user->getAttribute('hash', '')) | ||
| ->setAttribute('hashOptions', $isAnonymousUser ? Auth::DEFAULT_ALGO_OPTIONS : $user->getAttribute('hashOptions', '')) |
There was a problem hiding this comment.
Sorry, looks like we're going to change the behavior a bit.
- We don't want to update the password for users without a password
- We don't want to verify the password if the user doesn't have a password
stnguyen90
left a comment
There was a problem hiding this comment.
See my previous comment
What does this PR do?
Re-hash password using default algo on update phone (PATCH '/v1/account/phone' API call) if it's an anonymous user
Test Plan
Related PRs and Issues
#4990
Have you added your change to the Changelog?
Yes
Have you read the Contributing Guidelines on issues?
Yes