|
|
|
|
|
|
| |
This little script replaces and emails out a new password to a user dumb enough to lose theirs. I have NEVER done this (yeah, right!).
So make your user's lives easier by allowing them to do this, just place a 'lost password' link to a page with this script and thats it. It also flags the account with a temporary password marker that would force the user to change their password when they next log on. Keep that or lose it, its up to you.
|
<?
//ep.php
/*
resets and mails out a new temp password to the user
*/
session_start();
if (!isset($_SESSION['logged_in'])){
$_SESSION['logged_in'] = "";
}
//declarations
require("conn.php");
require("common.php");
global $err_msg;
$err_msg = "";
//control code
if (isset($_POST['cbSend'])){
mail_password();
}else{
show_form();
}//end if
//---------------------------------------------------------------------------------------
// mail password function
//---------------------------------------------------------------------------------------
function mail_password()
{
global $err_msg;
//get the variables from the form
if ((isset($_POST['email']))&&(isset($_POST['lg_name']))){
$email = $_POST['email'];
$mid = $_POST['lg_name'];
$date_cookie = $_COOKIE['last_time'];
}else{
$err_msg = "<b>Please enter both your email address and your username. Thank you.</b>";
show_form();
die();
}//end if
//create the sql and run the query
$sql = "SELECT * FROM users WHERE user_email='$email' and user_name = '$mid'";
$result = connect($sql);
//check the query results
if (mysql_num_rows($result)!=1){
$err_msg = "<font color=red>No results found. Please re-enter your username and email address to try again.</font>";
show_form();
}else{
$row = mysql_fetch_array($result);
$email2 = $row['cust_email'];
$pass = $row['cust_pw'];
//call the change password function and pass it the information related to the record to create the temp password
$new_pass = change_password($mid, $pass);
$sendto = $email2;
$from = "WebMaster <webmaster@domain.com>";
$subject = "Forgotten Password";
$message = "Dear $email2,
Your password is $new_pass.
Regards,
Webmaster";
echo $message;
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: php\n";
$headers .= "From: \"".$from."\" <".$from.">\n";
if (!mail($sendto, $subject, $message, $headers)){
echo "Mail failed to send";
}else{
header("location:confirm1.htm");
}//end if
}//end if
}//end function
//---------------------------------------------------------------------------------------
// change password function
//---------------------------------------------------------------------------------------
function change_password($id, $password)
{
//generate a random password
$pass = "";
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
//change the password in the db
$sql = "update cust_info set cust_pw ='".md5($pass)."', temp_pass = 1 where cust_lg = '$id' and cust_pw = '$password'";
$result = connect($sql);
if ($result){
return $pass;
}else{
change_password($id, $password);
}
}//end function
//---------------------------------------------------------------------------------------
// show_form function
//---------------------------------------------------------------------------------------
function show_form()
{
global $err_msg;
html_header();
?>
<CENTER><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 COLS=1 WIDTH="540" >
<TR>
<TD><FORM method="POST" action="<? echo $_SERVER['PHP_SELF'];?>">
<CENTER><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=3 WIDTH="549" HEIGHT="1" >
<TR>
<TD ALIGN=LEFT VALIGN=TOP >
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 COLS=1 WIDTH="500" >
<TR><TD><?echo $err_msg; ?></TD></TR>
<TR>
<TD><LEFT><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>Enter your Member ID and Email. Your Password will be emailed to you.</FONT></FONT></LEFT></TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD ALIGN=LEFT VALIGN=TOP>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 COLS=2 WIDTH="500" >
<TR>
<TD ALIGN=LEFT VALIGN=TOP WIDTH="75"><LEFT><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>Member ID</FONT></FONT></TD>
<TD><INPUT type="text" name="lg_name" size="40" value=""></LEFT></TD>
</TR>
<TR>
<TD ALIGN=LEFT VALIGN=TOP WIDTH="75"><LEFT><FONT FACE="Arial,Helvetica"><FONT SIZE=-1>Email</FONT></FONT></TD>
<TD><INPUT type="text" name="email" size="40" value=""></LEFT></TD>
</TR>
</TABLE>
<LEFT><INPUT type="submit" value="Send" name="cbSend"><INPUT type="button" value="Cancel" name="cbCancel" onclick="Javascript:history.back()"></LEFT></FORM></TD>
</TR>
<?
html_footer();
}//end function
?> | | |
|
| bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL, PHP, MySQL, Complete Programs, Databases | | | This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. Categories : Databases, MySQL, Complete Programs, PHP, Databases | | | A template script to provide the ability to get the next or previous n records from a MySQL database. Categories : Databases, PHP, MySQL | | | Cut your MySQL Connections to 1 line of code Categories : PHP, Beginner Guides, Databases, MySQL | | | Returns the last row from a select where multiple rows have been selected.
In this case it is used to determine the last number in an AUTO_INCREMENT column. I use it to create "ticket numbers" or anything that needs a unique ID in sequence. Categories : mSQL, MySQL, Databases, PHP | | | MySQL Connection/Query Class Categories : Databases, MySQL, PHP, PHP Classes | | | Complex paging with no resultset limit Categories : PHP, MySQL, Databases, Output Control, HTML and PHP | | | Phorum, MySQL, Language, UK date format, MySQL UK Date format Categories : PHP, Date Time, Strings, MySQL, Databases | | | BBS system for easy customization. Utilizes mySQL. Categories : Complete Programs, MySQL, PHP, Databases | | | Broadcast HTML Email Categories : PHP, Email, MySQL, Databases | | | Functions for loading images into a MySQL database and displaying them. Categories : Graphics, HTML and PHP, MySQL, PHP, Databases | | | for each record, do this to the first record, and do that to any subsequent record Categories : PHP, Databases, MySQL, Beginner Guides | | | PHP4 AND MySQL Authentication Categories : PHP, MySQL, Authentication, Databases | | | phpFormGenerator for Dynamic Form Generation from MySQL Categories : PHP, PHP Classes, MySQL, Databases, HTML and PHP | | | Zip code range and distance calculation class v1.0.0 Categories : PHP, Databases, MySQL, Zip Code | |
|
|