Jump to content

Recommended Posts

hi there,

 

i have a site that issues a password if you lose yours, but i cant get it to work , the code is below :

<? 
include 'db.php';
switch($_POST['recover']){ 
    default: 
    include 'lostpsw.php'; 
    break;
    case "recover": 
    recover_pw($_POST['email_address']); 
    break; 
} 
function recover_pw($email_address){ 
    if(!$email_address){ 
        echo "You forgot to enter your Email address"; 
        include 'lostpsw.php'; 
        exit(); 
    } 
    // quick check to see if record exists     
    $sql_check = mysql_query("SELECT * FROM users WHERE email_address='$email_address'"); 
    $sql_check_num = mysql_num_rows($sql_check); 
    if($sql_check_num == 0){ 
        echo "No records found matching your email address<br />"; 
        include 'lostpsw.php'; 
        exit(); 
    } 
    // Everything looks ok, generate password, update it and send it!
    function makeRandomPassword() { 
          $salt = "abchefghjkmnpqrstuvwxyz0123456789"; 
          srand((double)microtime()*1000000);  
          $i = 0; 
          while ($i <= 7) { 
                $num = rand() % 33; 
                $tmp = substr($salt, $num, 1); 
                $pass = $pass . $tmp; 
                $i++; 
          } 
          return $pass; 
    }
    $random_password = makeRandomPassword();
    $db_password = md5($random_password);
    $sql = mysql_query("UPDATE users SET password='$db_password' 
                WHERE email_address='$email_address'");
    $subject = "Your Password at The Truth Discovered!"; 
    $message = "Hi, we have reset your password.
    New Password: $random_password 
    http://www.thetruthdiscovered.com/login.php 
    Thanks! 
    The Webmaster 
    This is an automated response, please do not reply!"; 
    mail($email_address, $subject, $message, "From: The Truth Discovered Webmaster< admin@mydomain.com>\n 
        X-Mailer: PHP/" . phpversion()); 
    echo "Your password has been sent! Please check your email!<br />"; 
    include 'login.php'; 
} 
?> 

 

and the form is :

 

<?php include 'header.php'; ?>
<center>
<p align="center"><font face="Calligraphic" size="5" font color="white">New Password Request</font></p>
<form action="lost_pw.php" method="post"> 
<font face="Calligraphic" font color='white' size="4"> Email Address:<font color='white'>*</font>
<input type=text name='email_address' size=30><br><br><br>
<input type="submit" value="Get Password" name="submit"> 
</form>
</center>
<br><br>
<?php include 'footer.php'; ?>

 

when i enter an email address and hit the get password button , it flashes and stays on the page that i am entering the email at , any ideas?

 

Elaine

 

 

Link to comment
https://forums.phpfreaks.com/topic/46655-solved-lost-password-code-problem/
Share on other sites

Hmm, not sure.

PS: The default case will always be chosen, I.E. in your select it will never get to the process option.

 

switch($_POST['recover']){ 
    default: 
    include 'lostpsw.php'; 
    break;
    case "recover": 
    recover_pw($_POST['email_address']); 
    break; 
} 

 

Should be:

switch($_POST['recover']){ 
    case "recover":
{ 
    recover_pw($_POST['email_address']); 
    break;
} 
    default:
{ 
    include 'lostpsw.php'; 
    break;
}

} 

WHAT!!

 

The Switch statment was correct,

 

Hmm, not sure.

PS: The default case will always be chosen, I.E. in your select it will never get to the process option.

 

switch($_POST['recover']){ 
    default: 
    include 'lostpsw.php'; 
    break;
    case "recover": 
    recover_pw($_POST['email_address']); 
    break; 
} 

 

Should be:

switch($_POST['recover']){ 
    case "recover":
{ 
    recover_pw($_POST['email_address']); 
    break;
} 
    default:
{ 
    include 'lostpsw.php'; 
    break;
}

} 

header.php and footer.php

 

are the top and bottoms of my webpage that never changes, it has the menus and pictures ,

 

go see www.thetruthdiscovered.com :)

 

<?php include 'header.php'; ?>
<center>
<p align="center"><font face="Calligraphic" size="5" font color="white">New Password Request</font></p>
<form action="lost_pw.php" method="post"> 
<font face="Calligraphic" font color='white' size="4"> Email Address:<font color='white'>*</font>
<input type=text name='email_address' size=30><br><br><br>
<input type="submit" value="Get Password" name="submit"> 
</form>
</center>
<br><br>
<?php include 'footer.php'; ?>

 

it is as you said above :)

 

Elaine

 

 

 

OK try this

 


<?php
include 'db.php';
switch($_POST['recover']){ 
    default: 
    include 'lostpsw.php'; 
    break;
    case "recover": 
    recover_pw($_POST['email_address']); 
    break; 
} 

   // Everything looks ok, generate password, update it and send it!
    function makeRandomPassword() { 
          $salt = "abchefghjkmnpqrstuvwxyz0123456789"; 
          srand((double)microtime()*1000000);  
          $i = 0; 
          while ($i <= 7) { 
                $num = rand() % 33; 
                $tmp = substr($salt, $num, 1); 
                $pass = $pass . $tmp; 
                $i++; 
          } 
          return $pass; 
    }

function recover_pw($email_address){ 
    if(!$email_address){ 
        echo "You forgot to enter your Email address"; 
        include 'lostpsw.php'; 
        exit(); 
    } 
    // quick check to see if record exists     
    $sql_check = mysql_query("SELECT * FROM users WHERE email_address='$email_address'"); 
    $sql_check_num = mysql_num_rows($sql_check); 
    if($sql_check_num == 0){ 
        echo "No records found matching your email address<br />"; 
        include 'lostpsw.php'; 
        exit(); 
    }

    $random_password = makeRandomPassword();
    $db_password = md5($random_password);
    $sql = mysql_query("UPDATE users SET password='$db_password' 
                WHERE email_address='$email_address'");
    $subject = "Your Password at The Truth Discovered!"; 
    $message = "Hi, we have reset your password.
    New Password: $random_password 
    http://www.thetruthdiscovered.com/login.php 
    Thanks! 
    The Webmaster 
    This is an automated response, please do not reply!"; 
    mail($email_address, $subject, $message, "From: The Truth Discovered Webmaster< admin@mydomain.com>\n 
        X-Mailer: PHP/" . phpversion()); 
    echo "Your password has been sent! Please check your email!<br />"; 
    include 'login.php'; 
} 
?> 

I assume you got the message saying it was sent..

 

try another script

 

mailtest.php

$email_address = "your@email.com";
$subject = "Test";
$message = "Please Work";
$from = "From: The Truth Discovered Webmaster< admin@mydomain.com> X-Mailer: PHP/" . phpversion()"
$mailcheck = mail($email_address, $subject, $message, $from); 
if($mailcheck)
{
echo "Your password has been sent! Please check your email!<br />"; 
}else{
echo "email..failed<br />"; 
}

 

 

try that first see what happens

 

 

 

create a file called testmail.php

 

and copy and past the following into it

<?php

$email_address = "your@email.com";
$subject = "Test";
$message = "Please Work";
$from = "From: The Truth Discovered Webmaster< admin@mydomain.com> X-Mailer: PHP/" . phpversion()"
$mailcheck = mail($email_address, $subject, $message, $from); 
if($mailcheck)
{
echo "Your password has been sent! Please check your email!<br />"; 
}else{
echo "email..failed<br />"; 
}

?>

change your@email.com to your email

save

upload to server and run..

 

see if it work..

also check your junk mail folder

i get this

 

Parse error: parse error, unexpected '\"' in /home/www/thetruthdiscovered.com/testmail.php on line 5

 

mindu i dont see the unexpected \" anywhere!

 

 

 

You need a semicolon after and a double quote is missing.

$from = "From: The Truth Discovered Webmaster< admin@mydomain.com> X-Mailer: PHP/" . phpversion()"

 

oops

 

sorry i should of checked thats first

 

here try this (i tested it)


<?php

$email_address = "email@ghdagsdhj.com";
$subject = "Test";
$message = "Please Work";
$from = "From: The Truth Discovered Webmaster< admin@mydomain.com> X-Mailer: PHP" . phpversion();
$mailcheck = mail($email_address, $subject, $message, $from); 
if($mailcheck)
{
echo "Your password has been sent! Please check your email!<br />"; 
}else{
echo "email..failed<br />"; 
}

?>

i gives me the confirmation that it went through

 

but it never gets there , and you no the funny thing is ,

 

i just registered at my site with bogus information and another email address i have just to test if it is working on that page (register.php) and i got that email , but not the one you got me to test nor the one to reset the password, funny!

 

frustrating but i guess there is nothing else to do but laugh !

 

i want to thank you for all your help so far it is wonderful :)

 

but it doesnt make sense that the email goes through with the register.php , but not with the other ones can maybe my webhost limit me to one mail() function?

 

doesnt make sense

 

Elaine

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.