Skip to content

Modified PATCH '/v1/account/phone' API to re-hash password - #5003

Closed
harshmange44 wants to merge 3 commits into
appwrite:masterfrom
harshmange44:feat-4990-rehash-password-on-phone-update
Closed

harshmange44 wants to merge 3 commits into
appwrite:masterfrom
harshmange44:feat-4990-rehash-password-on-phone-update

Conversation

@harshmange44

Copy link
Copy Markdown

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

@harshmange44

harshmange44 commented Jan 13, 2023 •

Copy link
Copy Markdown
Author

Fixed #4990

@stnguyen90 stnguyen90 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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', ''))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please also make sure to update the hash and hashOptions attributes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@stnguyen90 Done, thanks for the review!

@stnguyen90 stnguyen90 linked an issue Jan 13, 2023 that may be closed by this pull request
2 tasks done
@stnguyen90
stnguyen90 self-requested a review January 13, 2023 20:12
Comment on lines +1637 to +1639
->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', ''))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Meldiron is this logic right? Is it supposed to be !$isAnonymousUser?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Meldiron,

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@stnguyen90 Any update, are we going to merge this one?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, looks like we're going to change the behavior a bit.

  1. We don't want to update the password for users without a password
  2. We don't want to verify the password if the user doesn't have a password

@stnguyen90
stnguyen90 requested a review from Meldiron January 13, 2023 20:15
@harshmange44
harshmange44 requested review from stnguyen90 and removed request for Meldiron January 15, 2023 14:14
Comment on lines +1637 to +1639
->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', ''))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, looks like we're going to change the behavior a bit.

  1. We don't want to update the password for users without a password
  2. We don't want to verify the password if the user doesn't have a password

@stnguyen90
stnguyen90 self-requested a review January 29, 2023 09:05

@stnguyen90 stnguyen90 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See my previous comment

@stnguyen90 stnguyen90 closed this May 25, 2023
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.

🚀 Feature: Re-hash Password on Phone Update

3 participants