WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Yet another random password generator with md5 encryption
Categories : PHP, MySQL, Databases
bastien koert
Date : Mar 02nd 2005
Grade : 3 of 5 (graded 9 times)
Viewed : 10137
File : No file for this code example.
Images : No Images for this code example.
Search : More code by bastien koert
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

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
mysql_escape_string
Categories : PHP, MySQL, Databases, Strings
Checks Date-Input from HTML-Forms and converts to YYYY-MM-DD Format for MySQL Date-Fields
Categories : MySQL, Date Time, PHP, Databases
myCSV-dump converts a simple CSV-flatfile-database into an MySQL-dump.
Categories : PHP, MySQL, Databases, Complete Programs
Authorize Me! An authentication script.
Categories : MySQL, Databases, Authentication, PHP
Multiple Search using PHP and Mysql
Categories : PHP, Databases, General SQL, MySQL
How to thread a list of messages in database and show it in a treelike structure
Categories : PHP, MySQL, Databases
How to Insert a Date Format Into MySQL from PHP
Categories : PHP, Databases, MySQL, Date Time, Beginner Guides
A very simple and efficient split bar the B-Z bar , for mysql and php ... Tired of obfuscated code try this one ...
Categories : PHP, Databases, MySQL, Algorithms
AITSH Download
Categories : PHP, Complete Programs, MySQL, Databases
Convert SQL from oracle,mysql,mssql,sqlite and odbc to SQL compatible
Categories : PHP, PHP Classes, Databases, MySQL, MS SQL Server
http://phpMySearch.web4.hm - The phpMySearch search engine system is a completeworld wide web indexing and searching system for a small domain or intranet.
Categories : Search Engines, PHP, Databases, MySQL
Paginating the mySQL data
Categories : PHP, Algorithms, Databases, MySQL, HTML and PHP
DDN FFA Network Script
Categories : PHP, MySQL, Complete Programs, HTML and PHP, Databases