Skip to content
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

Let user specify a new password (#13973) #15461

Closed
wants to merge 2 commits into from

Conversation

sdrenth
Copy link
Contributor

@sdrenth sdrenth commented Mar 5, 2021

What does it do?

This adds the possibility to let a user specify their own MODX password, using the same flow as the current manager Forgot password flow by sending a hashed link in the email which allows users to setup their new password.

Credits to @jonleverrier for coming up with this solution.

New password options:
Screenshot 2021-03-05 at 11 35 16

Set up password mail:
Screenshot 2021-03-05 at 10 20 48

Why is it needed?

There used to be an option to send an email to the MODX user which contains their MODX account password. This has been removed (for security purposes). This basically readds that functionality but in a saver way.

Related issue(s)/PR(s)

Sterc#22
#13973
Sterc#31

@cla-bot cla-bot bot added the cla-signed CLA confirmed for contributors to this PR. label Mar 5, 2021
@Ibochkarev
Copy link
Collaborator

@sdrenth please change target branch

@JoshuaLuckers JoshuaLuckers changed the base branch from 2.x to 3.x March 5, 2021 10:41
@sdrenth
Copy link
Contributor Author

sdrenth commented Mar 5, 2021

@JoshuaLuckers Thanks! :)

@sdrenth sdrenth changed the title Issue 13973 Let a user specify their own MODX password via email Mar 5, 2021
@Mark-H Mark-H changed the title Let a user specify their own MODX password via email Let user specify a new password (#13973) Mar 5, 2021
@Jako
Copy link
Collaborator

Jako commented Mar 5, 2021

Maybe the sendNotificationEmail method can be moved to a helper class instead of duplicating the code.

@sdrenth
Copy link
Contributor Author

sdrenth commented Mar 5, 2021

@Jako I agree with your comment but think that should be a separate issue, because the duplicate code was already in here (and there's more). Also where should the helper class be placed?

@JoshuaLuckers
Copy link
Contributor

The user needs access to the manager context, otherwise an access denied error will show up (only after you try to set your own password).

@sdrenth
Copy link
Contributor Author

sdrenth commented Mar 5, 2021

@JoshuaLuckers Is that just an FYI?

I would think that for frontend users you would have a registration form and a forgot password form. You don't want to guide those users to the manager part of the application.

I could also rename that option to "Let the user choose their own password via email (Needs manager access)" to clarify this?

What do you think?

@JoshuaLuckers
Copy link
Contributor

First of all, I like this new feature!

I'm having some doubts about the flow of this feature. If a user doesn't have access to the manager it still receives the email and the option to set the password. Only after setting your password you get the access denied message.

@Ibochkarev Ibochkarev added proposal Proposal about improvement aka RFC. Need to be discussed before start implementation. pr/review-needed Pull request requires review and testing. labels Mar 6, 2021
@Ibochkarev Ibochkarev added this to the v3.0.0-alpha3 milestone Mar 6, 2021
Copy link
Collaborator

@alroniks alroniks left a comment

Choose a reason for hiding this comment

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

I like the feature, but the code should be improved before merging.
I will do it if you don't mind.

@@ -200,3 +201,5 @@
$_lang['users'] = 'Users';
$_lang['user_createdon'] = 'Created On';
$_lang['user_createdon_desc'] = 'The date the user was created.';
$_lang['user_password_email_subject'] = 'Set up your password';
$_lang['user_password_email'] = '<h2>Set up your password</h2><p>We received a request to set up your MODX Revolution password. You can set up your password by clicking the button below and following the instructions on screen.</p><p class="center"><a href="[[+url_scheme]][[+http_host]][[+manager_url]]?modhash=[[+hash]]" class="btn">Set up my password</a></p><p class="small">If you did not send this request, please ignore this email.</p>';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's avoid using HTML tags inside lexicons. It becomes a hell while translating such stuff.

@@ -232,6 +233,52 @@ public function sendNotificationEmail() {
'html' => true,
]);
}

if ($this->getProperty('passwordgenmethod') === 'user_email_specify' && $this->modx->getService('hashing', modHashing::class)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It should be refactored, to move this implementation into a method to avoid such long if statement.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@sdrenth Please make changes to promote PR

@rthrash rthrash added this to 😬 Code Review in MODX 3.0.0-alpha Mar 11, 2021
@rthrash rthrash moved this from 😬 Code Review to 🤓 Doing in MODX 3.0.0-alpha Mar 11, 2021
@rthrash rthrash moved this from 🤓 Doing to 🤔 To Do in MODX 3.0.0-alpha Mar 11, 2021
@rthrash rthrash moved this from 🤔 To Do to 🤓 Doing in MODX 3.0.0-alpha Mar 25, 2021
@rthrash rthrash added this to Review in progress in MODX Revolution Beta 1 Apr 5, 2021
@rthrash rthrash moved this from 😬 Code Review to 🤓 Doing in MODX Revolution Beta 1 Apr 12, 2021
@opengeek opengeek modified the milestones: v3.0.0-alpha3, v3.0.0-beta1 Oct 27, 2021
@alroniks
Copy link
Collaborator

alroniks commented Nov 8, 2021

Looks like a new feature for including to the beta after the feature freeze. I suggest moving to 3.1
WDT @Mark-H, @opengeek?

@@ -232,6 +233,52 @@ public function sendNotificationEmail() {
'html' => true,
]);
}

if ($this->getProperty('passwordgenmethod') === 'user_email_specify' && $this->modx->getService('hashing', modHashing::class)) {
$activationHash = $this->modx->hashing->getHash('md5', 'hashing.modMD5', [])->hash($this->object->get('email') . '/' . $this->object->get('id'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not a secure hash/tokens and introduces a potential vulnerability. The scope would be limited because the "tokens" have a limited lifetime after manually being created by an admin, however it makes the hash very predictable.

In 3.x we can use random_bytes, so I would suggest:

$activationHash = bin2hex(random_bytes(32));

for a 64-character secure random token.

MODX Revolution Beta 1 automation moved this from 🤓 Doing to 😬 Code Review Jan 19, 2022
@Mark-H
Copy link
Collaborator

Mark-H commented Feb 10, 2024

As this PR has gone stale but this is still something that would be great to have, I've replaced it with a new one over at #16519.

@Mark-H Mark-H closed this Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed CLA confirmed for contributors to this PR. pr/review-needed Pull request requires review and testing. proposal Proposal about improvement aka RFC. Need to be discussed before start implementation.
Projects
MODX Revolution Beta 1
😬 Code Review
MODX 3.0.0-alpha
  
🤓 Doing
Development

Successfully merging this pull request may close these issues.

None yet

7 participants