Viewing file: emailpass2.php (2.38 KB) -rw-rw-rw- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?
//prevents caching
header("Expires: Sat, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: post-check=0, pre-check=0",false);
session_cache_limiter();
session_start();
//require the config file
require ("config.php");
//make the connection to the database
$connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error());
$db = @mysql_select_db($db_name,$connection)or die(mysql_error());
//build and issue the query
$sql ="SELECT * FROM $table_name WHERE email = '$_POST[email]'";
$result = @mysql_query($sql,$connection) or die(mysql_error());
//get the number of rows in the result set
$num = mysql_num_rows($result);
//If match was found, get username and email from database
if ($num != 0)
{
while ($sql = mysql_fetch_object($result))
{
$email = $sql -> email;
$uname = $sql -> username;
}
//Update database with new password
$newpass = rand(10000000,99999999);
$chng = "UPDATE $table_name SET
password = password('$newpass'), pchange = '1'
WHERE email = '$email'";
$result2 = @mysql_query($chng,$connection) or die(mysql_error());
//create message to user
$msg = "<p>Su nombre de usuario y contraseña han sido enviados a su email</p>";
//$msg .= "<p>Es rec.</p>";
$msg .= "<p></p>";
//$msg .= "<p><a href=\"login.html\">Login</a></p>";
//create mail message
$mailheaders = "From: www$domain\n";
$mailheaders .= "Su nombre de usuario es: $uname.\n";
$mailheaders .= "Su contraseña es: $newpass.\n";
//$mailheaders .= "$base_dir/login.html";
}
else
{
//If no email was found in the database send a notification to the admin
$email = $adminemail;
$msg = "<p>Su dirección de email no pudo ser encontrada</p>";
$msg .="<p>Se ha notificado al administrador del sitio, próximamente será contactado</p>";
$mailheaders = "From: www$domain\n";
$mailheaders .= "A user with the email address of $_POST[email] has requested a username and password reminder.\n";
$mailheaders .= "$_POST[email] could not be located in the database.\n";
}
//Email the request
$to = "$email";
$subject = "Nombre de usuario y contraseña";
mail($to, $subject, $mailheaders, "From: Secretaria de Ambiente<$adminemail>\n");
?>
<HTML>
<HEAD>
<TITLE>Solicitud de nombre de usuario y contraseña</TITLE>
</HEAD>
<BODY>
<? echo "$msg"; ?>
</BODY>
</HTML>
|