Techno World Inc - The Best Technical Encyclopedia Online!

THE TECHNO CLUB [ TECHNOWORLDINC.COM ] => PHP => Topic started by: Hellraiser on August 29, 2007, 10:42:01 AM



Title: PHP: Generate random passwords and send email to user
Post by: Hellraiser on August 29, 2007, 10:42:01 AM
Generate random passwords and send email to user

You can use this feature in the forgotPassword scenarios

I have used random passwords in a scenario where a user forgets his password and receives a temporary new password.

Generate random password -rand()

Code:
 $random=rand(1234,2343);
$password="mypass".$random;

Send email to user - mail()

Code:
$headers ="From: [email protected]\n"; //from address
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \n";
$subject ="Password Recovery - Do Not Reply Back To This Email";

$body="<div align=center><br><br>----------------------------- Password Recovery--------------------------------<br><br><br><br>Your Temporary Password is: $password<br><br>Remember your password this time!</div>";

if(mail($pemail,$subject,$body,$headers))
    {
        echo "<font class=tblackb>Your password has been send to $pemail</font>";
    }
else
    {
        echo "<font class=tblackb>Password Not Send.<br><Br>Please Try Again Later!...</font>";
    }


Save as sendpassword.php

Upload on the web and test it