3
« on: August 24, 2009, 22:00:33 »
Ok guys. Sorry for the long delay.. Here we go.... Remember this is a really dirty way to do this, maybe someone can create a better setup, but this is how I got it to work.
The barebone html:
<html>
<head>
<title>I Forgot My Password!</title>
<!-- Start CSS -->
<STYLE TYPE="text/css">
label{ width: 4em; float: left; text-align: right; margin-right: 0.5em; display: block }
.submit input{ margin-left: 4.5em; }
input{ color: #000; background: #E1F0F7; border: 1px solid #FF9900 }
.submit input{ color: #000; background: #FF9900; border: 2px outset #d7b9c9 }
fieldset{ border: 1px solid #FF9900; width: 20em }
legend{ color: #fff; background: #3089C5; border: 1px solid #3089C5; padding: 2px 6px }
body { color: #000; background: #fff; font-size="12";}
</STYLE
<!-- End CSS -->
</head>
<body>
<!-- Start top area -->
<img src="http://demo.loway.ch/queuemetrics-livedemo/img/sm_qm_logo.gif" align ="right">
<p> </p><hr>
<p>Please enter your username and press the submit button to have your password emailed to you.<p>
<p> </p>
<!-- End top area -->
<!-- Start form -->
<form method="post" action="passwd.php" >
<fieldset>
<legend>Forgot Password</legend>
<label for="username">Username:</label><br />
<input type="text" id="username" name="username" />
<br />
<label for="submit"> </label><br />
<input id="submit" name="submit" type="submit" value="submit" />
</fieldset>
</form>
<!-- End form -->
</html>
The php
<?php
error_reporting(E_ALL);
$username = $_POST['username'];
if (!preg_match('/^[a-zA-Z].*[0-9]*$/',$username)) {
echo "Invalid Entry! Please go back and try again. ";
exit;
}
$dbname = "queuemetrics";
$conn = mysql_connect ('localhost','login_name','password') or
die ('cannot connect to database error: '.mysql_error());
mysql_select_db ($dbname, $conn);
if($username != ""){
$sql = 'select PASSWORD from arch_users where login = "' . $username .'";';
$result = mysql_query($sql, $conn) or die(mysql_error());
$count=mysql_num_rows($result);
switch ($count) {
case 0;
echo "We're sorry, but we could not find that username.";
break;
case 1;
$userpass="";
while ($row = mysql_fetch_assoc($result)) {
$userpass=$row['PASSWORD'];
}
$subject = "Your Queuemetrics Login Information";
$message = "Your Password for logging into queuemetrics is:\n\n";
$message .= "Password: $userpass\n";
$to = "$username@domain.com";
$header = 'From: Helpdesk' . "\r\n" . 'Reply-To: no-reply@domain.com' . "\r\n";
if (mail($to, $subject, $message, $header)){
echo "Your Login credentials have been emailed to you.";
}
else {
echo "We're sorry, but we could not email your password because of a problem.";
}
}
}
else{
echo "No username provided";
}
?>
Creating the shortcut on the login page:
In the autenticazione.jsp file, search for this line:
<%= oH.button( oDec.k("logon_btn") + " » ", true, "", "qm_autentica", "" ) %>
Right after that make the following entry:
<p> </p>
<a href="http://localhost/apache2-default/passwd.html"><small>Forgot Password</small></a>
Hope this helps someone as much as it helped us.