Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Password Reset Script (PEAR/MySQL/MySQLi)

Newbie Spellweaver
Joined
Jun 12, 2011
Messages
95
Reaction score
35
This was requested by someone, so...

You will need PEAR packages for these to work.
Packages:
Mail:
Mail_Mime:

So what does this do?
Once a user has input their username and password, it'll send them an email with a link. If they click that link, it will change their password and email it to them.

Why have both MySQL and MySQLi?
Because I'm more familiar and comfortable coding with MySQL.

I'm using cPanel and I can't get it to work, help?!
Make sure you have the PEAR packages installed (can be found on cPanel dash), if you are still having problems then click the PHP Pear Packages in cPanel, find the Path and then add this to the file:
PHP:
ini_set('include_path','.:PATH'); // Replace PATH with your path

It sends the wrong links in the email?
Add this to your .htaccess
Code:
RewriteRule ^/account/password/reset/([^/]+)(|/)$ /forgotpassword.php?Reset=$1

What hash does this use?
md5.

What else do I need for this to work?
The table. Query this:
PHP:
CREATE TABLE IF NOT EXISTS `password_resets` (
  `username` varchar(50) NOT NULL,
  `hash` varchar(200) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Where is the code?
MySQL:
PHP:
<?PHP
require_once("config.php");
// Configuration
$SiteLink = "http://example.com/forgotpassword"; // File MUST be named forgotpassword.php unless you edit the code
$LogoLink = "http://images.habbo.com/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/1205/web-gallery/v2/images/habbologo_whiteR.gif";
$FromEmail = "from@lol.com";

if(isset($_GET['Reset'])) {
	$arr = explode("-", $_GET['Reset']);
	$Username = mysql_real_escape_string($arr[0]);
	$query = mysql_query("SELECT NULL FROM `password_resets` WHERE `username` = '". $Username ."' AND `hash` = '". mysql_real_escape_string($_GET['Reset']) ."'");
	if(mysql_num_rows($query) > 0)
	{ 
		$GetEmail = mysql_fetch_assoc(mysql_query("SELECT `mail` FROM `users` WHERE `username` = '". $Username ."'"));
		echo $GetEmail['mail'];
		GenerateNewPasswordEmail($Username, $GetEmail['mail']);
		mysql_query("DELETE FROM `password_resets` WHERE `username` ='". $Username ."'");
		echo "A new password has been sent to your email address."; die;
	}
	else {
		echo "Invalid hash."; 
		echo "SELECT NULL FROM `password_resets` WHERE `username` = '". $Username ."' AND `hash` = '". mysql_real_escape_string($_GET['Reset']) ."'";
		die;
	}
		
}
function GenerateValidationEmail($username, $email, $hash) {
global $SiteLink, $LogoLink;
SendMail($email, $username, '
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <style type="text/css">
    </style>
</head>

<body>

<table width="98%" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td align="center">

            <table border="0" cellpadding="0" cellspacing="0" width="595">
                <tr>
                    <td align="left" style="border-bottom: 1px solid #aaaaaa;" height="70" valign="middle">
                        <table border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td>
                                    <img src="'. $LogoLink .'" alt="Habbo" width="110" height="40" style="margin-left: 12px; display: block;" />
                                </td>
                            </tr>

                        </table>
                    </td>
                </tr>


<tr>
    <td align="left" style="border-bottom: 1px dashed #aaaaaa;"  valign="middle">
        <table style="margin-left: 12px; margin-right: 12px; padding: 0 0 10px 0; width: 100%;" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td valign="top">
                                    <p style="font-family: Verdana,Arial,sans-serif; font-size: 20px; padding-top: 15px;">
                                        Hello, '. $username .'
                                    </p>
                                    <p style="font-family: Verdana,Arial,sans-serif; font-size: 12px; padding-bottom: 5px;">
                                        To change your password please click <a href="'. $SiteLink .'/account/password/reset/'. $hash .'">this link to reset your password</a>.
                                    </p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
    <td align="left" style="border-bottom: 1px solid #aaaaaa;" height="100" valign="middle">
        <table style="margin-left: 12px;" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td valign="middle">
                    <table style="background-color: #51b708; height: 50px;" height="50px;" cellpadding="0" cellspacing="0">
                        <tr>
                            <td style="height: 100%; vertical-align:middle; border:solid 2px #000000" valign="middle">
                                <p style="font-family: Verdana,Arial,sans-serif; font-weight: bold; font-size: 18px; color:#ffffff; margin-top: 0; margin-bottom: 0;">
                                                <a style="text-decoration: none; padding:15px 20px; color:#ffffff" href="'. $SiteLink .'/account/password/reset/'. $hash .'">
                                                    Reset my Habbo password
                                                </a>
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
    <td valign="top" align="center">
        <table style="font-family: Verdana,Arial,sans-serif; text-align: justify; font-size:11px; color:#aaaaaa; padding-top: 10px;padding-right: 10px;padding-left: 10px;padding-bottom: 10px; margin-top: 0pt;margin-right: 0pt;margin-left: 0pt;margin-bottom: 0pt;" border="0" cellpadding="0" cellspacing="0" width="595">
            <tr>
                <td height="8"><!-- Dummy --></td>
            </tr>
            <tr>
                <td valign="top">
                                </td>
            </tr>
        </table>
    </td>
</tr>
</table>

</td>
</tr>
</table>
</body>
</html>');
} 

function GenerateNewPasswordEmail($username, $email) {
global $SiteLink, $LogoLink;
	$PlainPassword = substr (md5(uniqid(rand(),1)), 3, 10);
	$HashedPassword = md5($PlainPassword);
	mysql_query("UPDATE `users` SET `password` ='". $HashedPassword ."' WHERE `username` = '". $username ."'");
	SendMail($email, $username, '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <style type="text/css">
    </style>
</head>

<body>

<table width="98%" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td align="center">

            <table border="0" cellpadding="0" cellspacing="0" width="595">
                <tr>
                    <td align="left" style="border-bottom: 1px solid #aaaaaa;" height="70" valign="middle">
                        <table border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td>
                                    <img src="'. $LogoLink .'" alt="Habbo" width="110" height="40" style="margin-left: 12px; display: block;" />
                                </td>
                            </tr>

                        </table>
                    </td>
                </tr>


<tr>
    <td align="left" style="border-bottom: 1px dashed #aaaaaa;"  valign="middle">
        <table style="margin-left: 12px; margin-right: 12px; padding: 0 0 10px 0; width: 100%;" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td valign="top">
                                    <p style="font-family: Verdana,Arial,sans-serif; font-size: 20px; padding-top: 15px;">
                                        Hello, '. $username .'
                                    </p>
                                    <p style="font-family: Verdana,Arial,sans-serif; font-size: 12px; padding-bottom: 5px;">
                                       Your new password is: <b>'. $PlainPassword .'</b>
                                    </p>
</td>
</tr>
</table>
</td>
</tr>
<tr>

</tr>
<tr>
    <td valign="top" align="center">
        <table style="font-family: Verdana,Arial,sans-serif; text-align: justify; font-size:11px; color:#aaaaaa; padding-top: 10px;padding-right: 10px;padding-left: 10px;padding-bottom: 10px; margin-top: 0pt;margin-right: 0pt;margin-left: 0pt;margin-bottom: 0pt;" border="0" cellpadding="0" cellspacing="0" width="595">
            <tr>
                <td height="8"><!-- Dummy --></td>
            </tr>
            <tr>
                <td valign="top">
                                </td>
            </tr>
        </table>
    </td>
</tr>
</table>

</td>
</tr>
</table>
</body>
</html>');
	
	}
function SendMail($email, $username, $Body) {
global $FromEmail;
	require_once("Mail.php");
	require_once('Mail/mime.php');
	$headers = array('From' => $FromEmail, 'Subject' => "Password reset");
	$break = "\n";
	$mime = new Mail_mime($break);
	$mime->setHTMLBody($Body);
	$body = $mime->get();
	$headers = $mime->headers($headers);
	$mail = Mail::factory("mail");
	$mail->send($email, $headers, $body);
}
if(isset($_POST['actionForgot'])) {
//
$query = mysql_query("SELECT * FROM `users` WHERE `username` = '". mysql_real_escape_string($_POST['forgottenpw-username']). "' AND `mail` = '". mysql_real_escape_string($_POST['forgottenpw-email']) ."'");
if(mysql_num_rows($query) > 0) {
	$hash = mysql_real_escape_string($_POST['forgottenpw-username']) ."-". md5(uniqid(rand())). "-". sha1(md5(uniqid(rand()))) . "-" . md5(uniqid(rand())). "-" . md5(rand())  ;
	mysql_query("INSERT INTO `password_resets` (`username`, `hash`) VALUES ('". mysql_real_escape_string($_POST['forgottenpw-username']) ."', '". $hash."')") or die("INSERT INTO `password_resets` (`username`, `hash`) VALUES ('". mysql_real_escape_string($_POST['forgottenpw-username']) ."', '". mysql_real_escape_string($_POST['forgottenpw-username']) ."-". md5(uniqid(rand()))."'");
	GenerateValidationEmail(mysql_real_escape_string($_POST['forgottenpw-username']), mysql_real_escape_string($_POST['forgottenpw-email']), $hash);
}
else echo "Error"; 
die;
}

	
?><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
	<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
	<title>Hotelname ~ Home </title>
<link rel="stylesheet" href="http://images.habbo.com/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/1205/web-gallery/static/styles/common.css" type="text/css">
<link rel="stylesheet" href="http://images.habbo.com/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/1205/web-gallery/static/styles/process.css" type="text/css">

<body id="landing" class="process-template">

<div id="overlay"></div>

<div id="container">
	<div class="cb process-template-box clearfix"><div class="bt"><div></div></div><div class="i1"><div class="i2"><div class="i3">
		<div id="content">
			<div id="header" class="clearfix">
				<h1><a href="index.php"></a></h1>
			</div><style type="text/css">
		div.left-column { float: left; width: 50% }
		div.right-column { float: right; width: 49% }
		label { display: block }
		input { width: 98% }
		input.process-button { width: auto; float: right }
	</style>

			<div id="process-content">
	        	<div class="left-column">


<div class="cb clearfix"><div class="bt"><div></div></div><div class="i1"><div class="i2"><div class="i3">
    <div class="rounded-container"><div style="background-color: rgb(255, 255, 255); "><div style="margin: 0px 1px; height: 1px; overflow: hidden; background-color: rgb(255, 255, 255); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(253, 150, 87); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(255, 255, 255); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(253, 150, 87); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div><h2 class="title rounded-done">Forgotten Your Password?</h2><div style="background-color: rgb(255, 255, 255); "><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(253, 150, 87); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(255, 255, 255); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div><div style="margin: 0px 1px; height: 1px; overflow: hidden; background-color: rgb(255, 255, 255); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(253, 150, 87); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div></div></div></div>
    <div class="box-content">

        <p>Don't panic! Please enter your account information below and we'll send you an email telling you how to reset your password.</p>

        <div class="clear"></div>

        <form method="post" action="forgotpassword.php" id="forgottenpw-form">
            <p>
            <label for="forgottenpw-username">Username</label>
            <input type="text" name="forgottenpw-username" id="forgottenpw-username" value="">
            </p>

            <p>
            <label for="forgottenpw-email">Email address</label>
            <input type="text" name="forgottenpw-email" id="forgottenpw-email" value="">
            </p>

            <p>
            <input type="submit" value="Request information" name="actionForgot" class="submit process-button" id="forgottenpw-submit">
            </p>
            <input type="hidden" value="default" name="origin">
        </form>
    </div>
</div></div></div><div class="bb"><div></div></div></div>

</div>


<div class="right-column">

<div class="cb clearfix"><div class="bt"><div></div></div><div class="i1"><div class="i2"><div class="i3">
    <div class="rounded-container"><div style="background-color: rgb(255, 255, 255); "><div style="margin: 0px 1px; height: 1px; overflow: hidden; background-color: rgb(255, 255, 255); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(253, 150, 87); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(255, 255, 255); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(253, 150, 87); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div><h2 class="title rounded-done">False Alarm!</h2><div style="background-color: rgb(255, 255, 255); "><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(253, 150, 87); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(255, 255, 255); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div><div style="margin: 0px 1px; height: 1px; overflow: hidden; background-color: rgb(255, 255, 255); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(253, 150, 87); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div></div></div></div>
    <div class="box-content">
        <p>If you have remembered your password, or if you just came here by accident, click the link below to return to the homepage.</p>
        <p><a href="index.php">Back to homepage</a></p>
    </div>
</div></div></div><div class="bb"><div></div></div></div>

</div>


<!--[if lt IE 7]>
<script type="text/javascript">
Pngfix.doPngImageFix();
</script>
<![endif]-->

<div id="footer">
	<p><a href="index.php" target="_self">Homepage</a> </p>
		<p>HABBO is a registered trademark of Sulake Corporation. All rights reserved to their respective owner(s).</p>
	</div>			</div>
        </div>
    </div></div></div><div class="bb"><div></div></div></div>
</div>



</body></html>

MySQLi:
PHP:
<?PHP
// Configuration 
$SiteLink = "http://example.com/forgotpassword"; // File MUST be named forgotpassword.php unless you edit the code
$LogoLink = "http://images.habbo.com/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/1205/web-gallery/v2/images/habbologo_whiteR.gif";
$FromEmail = "from@lol.com";
$host = ""; // Host
$name = ""; // User name
$pass = ""; // Password
$dbname = ""; // Database name
$mysqli = new mysqli($host, $name, $pass, $dbname);
if(isset($_GET['Reset'])) {
	$arr = explode("-", $_GET['Reset']);
	$Username = $mysqli->real_escape_string($arr[0]);
	$query = mysqli_query($mysqli, "SELECT NULL FROM `password_resets` WHERE `username` = '". $Username ."' AND `hash` = '". $mysqli->real_escape_string($_GET['Reset']) ."'");
	$querycount = $query->num_rows;
	if($querycount > 0)
	{ 
		$GetEmai = mysqli_query($mysqli, "SELECT `mail` FROM `users` WHERE `username` = '". $Username ."'");
		$GetEmail = $GetEmai->fetch_assoc();
		echo $GetEmail['mail'];
		GenerateNewPasswordEmail($Username, $GetEmail['mail']);
		mysqli_query($mysqli, "DELETE FROM `password_resets` WHERE `username` ='". $Username ."'");
		echo "A new password has been sent to your email address."; die;
	}
	else {
		echo "Invalid hash."; 
		echo "SELECT NULL FROM `password_resets` WHERE `username` = '". $Username ."' AND `hash` = '". $mysqli->real_escape_string($_GET['Reset']) ."'";
		die;
	}
		
}
function GenerateValidationEmail($username, $email, $hash) {
global $SiteLink, $LogoLink;
SendMail($email, $username, '
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <style type="text/css">
    </style>
</head>

<body>

<table width="98%" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td align="center">

            <table border="0" cellpadding="0" cellspacing="0" width="595">
                <tr>
                    <td align="left" style="border-bottom: 1px solid #aaaaaa;" height="70" valign="middle">
                        <table border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td>
                                    <img src="'. $LogoLink .'" alt="Habbo" width="110" height="40" style="margin-left: 12px; display: block;" />
                                </td>
                            </tr>

                        </table>
                    </td>
                </tr>


<tr>
    <td align="left" style="border-bottom: 1px dashed #aaaaaa;"  valign="middle">
        <table style="margin-left: 12px; margin-right: 12px; padding: 0 0 10px 0; width: 100%;" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td valign="top">
                                    <p style="font-family: Verdana,Arial,sans-serif; font-size: 20px; padding-top: 15px;">
                                        Hello, '. $username .'
                                    </p>
                                    <p style="font-family: Verdana,Arial,sans-serif; font-size: 12px; padding-bottom: 5px;">
                                        To change your password please click <a href="'. $SiteLink .'/account/password/reset/'. $hash .'">this link to reset your password</a>.
                                    </p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
    <td align="left" style="border-bottom: 1px solid #aaaaaa;" height="100" valign="middle">
        <table style="margin-left: 12px;" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td valign="middle">
                    <table style="background-color: #51b708; height: 50px;" height="50px;" cellpadding="0" cellspacing="0">
                        <tr>
                            <td style="height: 100%; vertical-align:middle; border:solid 2px #000000" valign="middle">
                                <p style="font-family: Verdana,Arial,sans-serif; font-weight: bold; font-size: 18px; color:#ffffff; margin-top: 0; margin-bottom: 0;">
                                                <a style="text-decoration: none; padding:15px 20px; color:#ffffff" href="'. $SiteLink .'/account/password/reset/'. $hash .'">
                                                    Reset my Habbo password
                                                </a>
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
    <td valign="top" align="center">
        <table style="font-family: Verdana,Arial,sans-serif; text-align: justify; font-size:11px; color:#aaaaaa; padding-top: 10px;padding-right: 10px;padding-left: 10px;padding-bottom: 10px; margin-top: 0pt;margin-right: 0pt;margin-left: 0pt;margin-bottom: 0pt;" border="0" cellpadding="0" cellspacing="0" width="595">
            <tr>
                <td height="8"><!-- Dummy --></td>
            </tr>
            <tr>
                <td valign="top">
                                </td>
            </tr>
        </table>
    </td>
</tr>
</table>

</td>
</tr>
</table>
</body>
</html>');
} 

function GenerateNewPasswordEmail($username, $email) {
global $mysqli, $LogoLink;
	$PlainPassword = substr (md5(uniqid(rand(),1)), 3, 10);
	$HashedPassword = md5($PlainPassword);
	$query = mysqli_query($mysqli, "UPDATE `users` SET `password` ='". $HashedPassword ."' WHERE `username` = '". $username ."'");
	SendMail($email, $username, '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <style type="text/css">
    </style>
</head>

<body>

<table width="98%" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td align="center">

            <table border="0" cellpadding="0" cellspacing="0" width="595">
                <tr>
                    <td align="left" style="border-bottom: 1px solid #aaaaaa;" height="70" valign="middle">
                        <table border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td>
                                    <img src="'. $LogoLink .'" alt="Habbo" width="110" height="40" style="margin-left: 12px; display: block;" />
                                </td>
                            </tr>

                        </table>
                    </td>
                </tr>


<tr>
    <td align="left" style="border-bottom: 1px dashed #aaaaaa;"  valign="middle">
        <table style="margin-left: 12px; margin-right: 12px; padding: 0 0 10px 0; width: 100%;" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td valign="top">
                                    <p style="font-family: Verdana,Arial,sans-serif; font-size: 20px; padding-top: 15px;">
                                        Hello, '. $username .'
                                    </p>
                                    <p style="font-family: Verdana,Arial,sans-serif; font-size: 12px; padding-bottom: 5px;">
                                       Your new password is: <b>'. $PlainPassword .'</b>
                                    </p>
</td>
</tr>
</table>
</td>
</tr>
<tr>

</tr>
<tr>
    <td valign="top" align="center">
        <table style="font-family: Verdana,Arial,sans-serif; text-align: justify; font-size:11px; color:#aaaaaa; padding-top: 10px;padding-right: 10px;padding-left: 10px;padding-bottom: 10px; margin-top: 0pt;margin-right: 0pt;margin-left: 0pt;margin-bottom: 0pt;" border="0" cellpadding="0" cellspacing="0" width="595">
            <tr>
                <td height="8"><!-- Dummy --></td>
            </tr>
            <tr>
                <td valign="top">
                                </td>
            </tr>
        </table>
    </td>
</tr>
</table>

</td>
</tr>
</table>
</body>
</html>');
	
	}
function SendMail($email, $username, $Body) {
global $FromEmail;
	require_once("Mail.php");
	require_once('Mail/mime.php');
	$headers = array('From' => $FromEmail, 'Subject' => "Password reset");
	//$GenBody = BodyGenerate($username, $hash);
	$break = "\n";
	$mime = new Mail_mime($break);
	$mime->setHTMLBody($Body);
	$body = $mime->get();
	$headers = $mime->headers($headers);
	$mail = Mail::factory("mail");
	$mail->send($email, $headers, $body);
}
if(isset($_POST['actionForgot'])) {
//
$query = mysqli_query($mysqli, "SELECT * FROM `users` WHERE `username` = '". $mysqli->real_escape_string($_POST['forgottenpw-username']). "' AND `mail` = '". $mysqli->real_escape_string($_POST['forgottenpw-email']) ."'");
$querycount = $query->num_rows;
if($querycount > 0) {
	$hash = $mysqli->real_escape_string($_POST['forgottenpw-username']) ."-". md5(uniqid(rand())). "-". sha1(md5(uniqid(rand()))) . "-" . md5(uniqid(rand())). "-" . md5(rand())  ;
	mysqli_query($mysqli, "INSERT INTO `password_resets` (`username`, `hash`) VALUES ('". $mysqli->real_escape_string($_POST['forgottenpw-username']) ."', '". $hash."')") or die("INSERT INTO `password_resets` (`username`, `hash`) VALUES ('". $mysqli->real_escape_string($_POST['forgottenpw-username']) ."', '". $mysqli->real_escape_string($_POST['forgottenpw-username']) ."-". md5(uniqid(rand()))."'");
	GenerateValidationEmail($mysqli->real_escape_string($_POST['forgottenpw-username']), $mysqli->real_escape_string($_POST['forgottenpw-email']), $hash);
}
else echo "Error"; 
die;
}

	
?><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
	<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
	<title>Hotelname ~ Home </title>
<link rel="stylesheet" href="http://images.habbo.com/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/1205/web-gallery/static/styles/common.css" type="text/css">
<link rel="stylesheet" href="http://images.habbo.com/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/1205/web-gallery/static/styles/process.css" type="text/css">

<body id="landing" class="process-template">

<div id="overlay"></div>

<div id="container">
	<div class="cb process-template-box clearfix"><div class="bt"><div></div></div><div class="i1"><div class="i2"><div class="i3">
		<div id="content">
			<div id="header" class="clearfix">
				<h1><a href="index.php"></a></h1>
			</div><style type="text/css">
		div.left-column { float: left; width: 50% }
		div.right-column { float: right; width: 49% }
		label { display: block }
		input { width: 98% }
		input.process-button { width: auto; float: right }
	</style>

			<div id="process-content">
	        	<div class="left-column">


<div class="cb clearfix"><div class="bt"><div></div></div><div class="i1"><div class="i2"><div class="i3">
    <div class="rounded-container"><div style="background-color: rgb(255, 255, 255); "><div style="margin: 0px 1px; height: 1px; overflow: hidden; background-color: rgb(255, 255, 255); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(253, 150, 87); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(255, 255, 255); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(253, 150, 87); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div><h2 class="title rounded-done">Forgotten Your Password?</h2><div style="background-color: rgb(255, 255, 255); "><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(253, 150, 87); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(255, 255, 255); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div><div style="margin: 0px 1px; height: 1px; overflow: hidden; background-color: rgb(255, 255, 255); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(253, 150, 87); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div></div></div></div>
    <div class="box-content">

        <p>Don't panic! Please enter your account information below and we'll send you an email telling you how to reset your password.</p>

        <div class="clear"></div>

        <form method="post" action="forgotpassword.php" id="forgottenpw-form">
            <p>
            <label for="forgottenpw-username">Username</label>
            <input type="text" name="forgottenpw-username" id="forgottenpw-username" value="">
            </p>

            <p>
            <label for="forgottenpw-email">Email address</label>
            <input type="text" name="forgottenpw-email" id="forgottenpw-email" value="">
            </p>

            <p>
            <input type="submit" value="Request information" name="actionForgot" class="submit process-button" id="forgottenpw-submit">
            </p>
            <input type="hidden" value="default" name="origin">
        </form>
    </div>
</div></div></div><div class="bb"><div></div></div></div>

</div>


<div class="right-column">

<div class="cb clearfix"><div class="bt"><div></div></div><div class="i1"><div class="i2"><div class="i3">
    <div class="rounded-container"><div style="background-color: rgb(255, 255, 255); "><div style="margin: 0px 1px; height: 1px; overflow: hidden; background-color: rgb(255, 255, 255); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(253, 150, 87); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(255, 255, 255); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(253, 150, 87); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div><h2 class="title rounded-done">False Alarm!</h2><div style="background-color: rgb(255, 255, 255); "><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(253, 150, 87); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div><div style="margin: 0px; height: 1px; overflow: hidden; background-color: rgb(255, 255, 255); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div><div style="margin: 0px 1px; height: 1px; overflow: hidden; background-color: rgb(255, 255, 255); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(253, 150, 87); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 108, 20); "><div style="height: 1px; overflow: hidden; margin: 0px 1px; background-color: rgb(252, 98, 4); "></div></div></div></div></div></div>
    <div class="box-content">
        <p>If you have remembered your password, or if you just came here by accident, click the link below to return to the homepage.</p>
        <p><a href="index.php">Back to homepage</a></p>
    </div>
</div></div></div><div class="bb"><div></div></div></div>

</div>


<!--[if lt IE 7]>
<script type="text/javascript">
Pngfix.doPngImageFix();
</script>
<![endif]-->

<div id="footer">
	<p><a href="index.php" target="_self">Homepage</a> </p>
		<p>HABBO is a registered trademark of Sulake Corporation. All rights reserved to their respective owner(s).</p>
	</div>			</div>
        </div>
    </div></div></div><div class="bb"><div></div></div></div>
</div>



</body></html>
 
Newbie Spellweaver
Joined
Jun 12, 2011
Messages
95
Reaction score
35
Kinda matters. Messy makes it unsecured? Lol Or just makes exploits.
No it doesn't.. lol.
So you prefer to present yourself as a person who just copies and pastes codes or doesn't code anything properly? Right..

Copies and pastes? What? lol.

You've gone from "messy" to copy and pasting, make your mind up.

PS: It is the Habbo section, what is actually done properly here?

It didn't take me long to code it. I could of spent a little longer cleaning it, but why should I bother?

People will only say "thanks" and that's that.
 
Zephyr Studios
Loyal Member
Joined
Feb 18, 2012
Messages
1,877
Reaction score
724
Good job man! Could you also make a "Remember me" thing? :D
 
╰☆ Learning PHP
Joined
Jul 6, 2012
Messages
190
Reaction score
74
I got an error :

PHP:
 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\forgotpassword.php on line 209
Error
 
Joined
Oct 28, 2008
Messages
1,558
Reaction score
368
nice job nathan, could've done it myself, but will give me an idea for when utCMS get's to this stage (start the login, register, password reset ect).
 
Skilled Illusionist
Joined
May 7, 2011
Messages
342
Reaction score
25
Good job this is verry nice, and this deserves a +1 like <3
 
Joined
Jun 23, 2010
Messages
2,357
Reaction score
2,198
Lol duck it, it works so who cares how messy it is.
I do, you also dont give your teacher a peace of junk for a asignment or for a company, deliver half the work?Also coding cleaner is only easier to understand, also for others. As the main goal (in my opinion) is to learn of private developments.
 
Newbie Spellweaver
Joined
Jun 12, 2011
Messages
95
Reaction score
35
I do, you also dont give your teacher a peace of junk for a asignment or for a company, deliver half the work?Also coding cleaner is only easier to understand, also for others. As the main goal (in my opinion) is to learn of private developments.


How many people do you think will "learn" from this? Most people will just add it and that's that, not even looking at the code.

I do, you also dont give your teacher a peace of junk for a asignment or for a company, deliver half the work?
We're in the Habbo section sir.
 
Newbie Spellweaver
Joined
Nov 25, 2011
Messages
7
Reaction score
0
Uhm.. please help me i have an error :

Code:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in H:\xampp\htdocs\forgotpassword.php on line 209
Error

This is really cool if i get it to work pleeease (also i use PhoenixPHP) sorry for bad english and please don't say im stupid because i use PhoenixPHP, i knoow ! :blushing:
 
Web & Interaction Design
Loyal Member
Joined
Dec 18, 2010
Messages
1,506
Reaction score
712
To be fair, anyone who will appreciate and value tidy code will be able to fix up this for themselves if they want to use it. So, quit moaning - Jos' point was still valid however, but that's a whole different context.
 
╰☆ Learning PHP
Joined
Jul 6, 2012
Messages
190
Reaction score
74
Guys i have an error pleasse help me :
PHP:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in H:\xampp\htdocs\forgotpassword.php on line 209
Error
 
Back
Top