Page 1 of 1

reset forgotten password using php..

Posted: Mon Mar 30, 2009 7:30 am
by pavanpuligandla
hii all,
i'm developing a script that emails a random link to user's email when an user has forgotten his/her password.,
the problem is, i want to insert a random key in my database key column against the same user who has clicked forgot password link, after inserting the same i should invoke php mail to send the URL who has lost password..
now after running the below script on my server, i can see URL in plain text printed same as in the script. can anyone please help me, how to achieve those 2 operations(inserting a random key into DB against an user who clicks forgot password, email valid URL to user)..

Code: Select all

<?php
 session_start();
 
 //Connect to mysql server
    $link=mysql_connect("localhost","root","");
    if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
    }
    //Select database
    $db=mysql_select_db("blackerdread");
    if(!$db) {
        die("Unable to select database");
    }
 
 if(!get_magic_quotes_gpc())
 {
    $row['customerID'] = stripslashes($_POST[$row['customerID']]);
 }else{
    $row['customerID'] = $_POST[$row['customerID']];
    
 }
    
    $key = substr(base64_encode(crypt('', '')), 0, 32);
    $query1="INSERT INTO ss_customers (key) VALUES ('$key') WHERE customerID='8'";
     $result1=mysql_query($query1);
     
     $query = "SELECT Login, Email FROM ss_customers WHERE customerID='8'";
      $result=mysql_query($query);
      $row = mysql_fetch_array($result);
          if(mysql_num_rows($result)>0) 
            {
            $Email = $row['Email'];
            $Login = $row['Login'];
            $headers4="admin@blackerdread.com"; // Change this address within quotes to your address
            $headers.="Reply-to: $headers4\n";
            $headers .= "From: $headers4\n";
            $headers .= "Errors-to: $headers4\n";
 
 
// mail funciton will return true if it is successful
if(mail("$Email","Your Request for login details","This is in response to your request for login detailst at site_name \n \nLogin ID: $Login \n URL . resetpassword.php?page=reset-password&Login= . urlencode($Login) . &key= . urlencode($key) . \r\n . \n\n Thank You \n \n siteadmin","$headers")){echo "<center><font face='Verdana' size='2' ><b>THANK YOU</b> <br>Your password is posted to your emil address . Please check your mail after some time. </center>";}
else{// there is a system problem in sending mail
echo " <center><font face='Verdana' size='2' color=red >There is some system problem in sending login details to your address. Please contact site-admin. <br><br><input type='button' value='Retry' onClick='history.go(-1)'></center></font>";}
    }
    else {
        echo "mail not sent";
    }