Store the password question and answer in the DB. When you need to verify just call the info from the DB and match it with the info they entered.
====passwordrecovery.php====
<FORM ACTION = "verifyscreen.php" METHOD = "POST">
Enter your username: <INPUT TYPE = "TEXT" NAME = "username">
Enter the email you wish to send the password to: <INPUT TYPE = "TEXT" NAME = "email">
<INPUT TYPE = "SUBMIT">
</FORM>
====example of verifyscreen.php====
<?php
//connect to DB
@mysql_connect('localhost', 'dbusername', 'dbpass');
@mysql_select_db('DB');
//call info from DB
$query = "SELECT password, passquestion, passanswer FROM yourtablehere WHERE id = '$username'";
$result = mysql_query($query);
while($passinfo = mysql_fetch_array($result, MYSQL_ASSOC){
//question
echo("Password question for, ".$passinfo[\"username\"].".<p>");
echo($passinfo["passquestion"]);
}
?>
<FORM ACTION = "verify.php" METHOD = "POST">
Answer: <INPUT TYPE = "TEXT" NAME = "verifyanswer">
<INPUT TYPE = "SUBMIT">
</FORM>
====example of verify.php====
<?php
if($verifyanswer == $passinfo["passanswer"]){
mail("$email", "Your password is $passinfo[\"password\"]", "From: youremail@ddress.com\r\nReply-to:youremail@ddress.com");
echo("Your password has been sent to ".$email.".");
}
else {
echo("The answer you entered was not correct, try again.");