Jump to content


Recommended Posts

I got this from the forum here (probably Ryan) which might help.

    $showForm = true; 
    $email = $sanitizer->email($input->post->email);
    if($email) {
      $u = $users->get("email=$email"); 
      if($u->id) {
        // generate a random, temporary password
        $pass = '';
        $chars = 'abcdefghjkmnopqrstuvwxyz23456789'; // add more as you see fit
        $length = mt_rand(9,12); // password between 9 and 12 characters
        for($n = 0; $n < $length; $n++) $pass .= $chars[mt_rand(0, strlen($chars)-1)];
        $u->tmp_pass = $pass; // populate a temporary pass to their profile
        $message = "Your new password on the blah blah web site is: $pass\n";
        //$message .= "Please change it after you login.";
        mail($u->email, "Password reset", $message, "From: noreply@{$config->httpHost}"); 
        $page->body = "<p>An email has been dispatched to you with further instructions.</p>";
        $showForm = false;
      } else {
        $page->body = "<p>Sorry, account doesn't exist or doesn't have an email.</p>";

    if($showForm) $page->body .= "
      <h2>Reset your password</h2>
      <form action='./' method='post'>
      <label>E-Mail <input type='email' name='email'></label>
      <input type='submit' value='Submit'>
      <p class='spam-check'>Please check your spam folder in case this email doesn't appear within 10 minutes.</p>

    // include the main HTML/markup template that outputs at least $page->body in an HTML document
    echo $page->body;


  • Like 1
Link to comment
Share on other sites

Thanks Marty

I can see how that works, but I'm really not keen on outputting raw passwords to the screen or an email.

I'd really like to be able to replicate the back-end 'Forgotten Password' feature somehow.

I've had a look in the ProcessForgotPassword file and there doesn't appear to be anything too complex, I'm just not entirely sure how it's bound to the back-end login in such a way to be invoked from http://<hostname>/<admin>/?forgot=1

Link to comment
Share on other sites

OK I feel like a n00b now!

This simple bit of code seems to work anywhere in the front-end:

if ($this->modules->isInstalled('ProcessForgotPassword')) echo $this->modules->get("ProcessForgotPassword")->execute();

Obviously it should be attached to a link and used in the same context as in the backend... but It generates the bare unstyled forms, and seems to handle all the functionality perfectly.

  • Like 3
Link to comment
Share on other sites

It's part of the core, so no question of it being stable.

I've not had a chance to integrate it properly, but you can see for yourself in the ProcessForgotPassword.php it keeps you on the same page so in theory can be used in any part of the site.

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...