Location: PHPKode > projects > Admbook > lost.php
<?php
	include("settings-data.php");
	include("lib.php");
	include("users-data.php");
	session_start();
	if (!isset($send))
		$send = false;
	$warning = "";
	if (!isset($currentLogin))
		$currentLogin = "";
	if (!isset($currentMail))
		$currentMail = "";
	$currentPassword = "";
	$error = "";
	$style = "";

	if ($send)
	{
		$currentLogin = translateHtml($currentLogin, false);
		$currentMail = translateHtml($currentMail, false);
		if ($currentLogin == "")
		{
			$error .= "Login is empty<br/>";
			$style .= "\n.login {\n\tcolor : ".$constant['error-color']."\n}\n";
		}
		else if (strlen($currentLogin) > 30)
		{
			$error .= "Login is long<br/>";
			$style .= "\n.login {\n\tcolor : ".$constant['error-color']."\n}\n";
		}
		if ($currentMail == "")
		{
			$error .= "e-mail is empty<br/>";
			$style .= "\n.email {\n\tcolor : ".$constant['error-color']."\n}\n";
		}
		else if (!validEmail($currentMail))
		{
			$error .= "Wrong e-mail <br/>";
			$style .= "\n.email {\n\tcolor : ".$constant['error-color']."\n}\n";
		}
		else if (strlen($currentMail) > 128)
		{
			$error .= "e-mail is long<br/>";
			$style .= "\n.email {\n\tcolor : ".$constant['error-color']."\n}\n";
		}
		if ($error == "")
		{
			$check = false;
			foreach($user as $key1 => $value1)
			{
				foreach ($value1 as $key2 => $value2)
				{
					if ($key2 == "name" && $currentLogin == $value2)
					{
						$userKey = $key1;
						break 2;
					}
				}
			}
			if ($currentLogin == $user[$userKey]['name'] && $currentMail == $user[$userKey]['mail'])
			{
				$check = true;
			}
			if (!$check)
			{
				$error .= "Unknown user<br/>";
			}
			else
			{
				$currentPassword = generatePassword(8);
				$md5CurrentPassword = md5($currentPassword);
				$user[$userKey]['password'] = $md5CurrentPassword;
				$contentCnt = sizeof($user);
				$updateContent = "<?php\n";
				for($i = 0; $i < $contentCnt; $i++)
				{
					while(list($key, $value) = each($user[$i]))
					{
						$updateContent .= "\t\$user[".$i."]['".$key."'] = \"".$value."\";\n";
					}
					if ($i != $contentCnt-1)
						$updateContent .= "\n";
				}
				$updateContent .= "?>";
				$mailBody = "login: ".$user[$userKey]['name']."\n";
				$mailBody .= "password: ".$currentPassword."\n";
				$mailBody .= "Password was sent with this link http://".$HTTP_HOST.$SCRIPT_NAME;
				if (@mail($user[$userKey]['mail'], "guestbook: lost password?", $mailBody, "Content-Type: text/plain; charset=windows-1251\nContent-Transfer-Encoding: 8bit"))
					reWriteDataInFile ($updateContent,"users-data.php");
			}
		}
	}
?>
<html>
<head>
<title>admbook :: version <?=$constant['version']?></title>
<?php
	if ($constant['charset'] != "")
	{
?>
<meta http-equiv="Content-Type" content="text/html; charset=<?=$constant['charset']?>"/>
<?php
	}
?>
<link href="style.css" type="text/css" rel="stylesheet"/>
<style type="text/css">
<!--
#error {
	color : <?=$constant['error-color']?>
}

.text {
	font : 8pt "Verdana","Arial Cyr", "Arial","Tahoma","Helvetica", sans-serif;
	color : <?=$constant['text-color']?>
}

.link {
	font : 8pt "Verdana","Arial Cyr", "Arial","Tahoma","Helvetica", sans-serif;
	color : <?=$constant['link-color']?>
}

.messagetext {
	font : 8pt "Verdana","Arial Cyr", "Arial","Tahoma","Helvetica", sans-serif;
	color : <?=$constant['message-text-color']?>
}

.messagelink {
	font : 8pt "Verdana","Arial Cyr", "Arial","Tahoma","Helvetica", sans-serif;
	color : <?=$constant['message-link-color']?>
}

.admintext {
	font : 8pt "Verdana","Arial Cyr", "Arial","Tahoma","Helvetica", sans-serif;
	color : <?=$constant['admin-message-text-color']?>
}

.adminlink {
	font : 8pt "Verdana","Arial Cyr", "Arial","Tahoma","Helvetica", sans-serif;
	color : <?=$constant['admin-message-link-color']?>
}

.headertext {
	font : 8pt "Verdana","Arial Cyr", "Arial","Tahoma","Helvetica", sans-serif;
	color : <?=$constant['header-text-color']?>
}

.headerlink {
	font : 8pt "Verdana","Arial Cyr", "Arial","Tahoma","Helvetica", sans-serif;
	color : <?=$constant['header-link-color']?>
}

<?=$style?>
-->
</style>
</head>
<body bgcolor="<?=$constant['background-color']?>" text="<?=$constant['text-color']?>" link="<?=$constant['link-color']?>" vlink="<?=$constant['link-color']?>" alink="<?=$constant['link-color']?>" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0">
<table width="760" border="0" cellpadding="0" cellspacing="2" height="100%" align="center">
<form action="lost.php" method="post">
<input type="hidden" name="send" value="true"/>
<tr>
	<td valign="top" class="text" height="1">
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td bgcolor="<?=$constant['border-color']?>">
				<table width="100%" border="0" cellpadding="2" cellspacing="1">
				<tr>
					<td bgcolor="<?=$constant['header-background-color']?>" class="headertext" id="book-title">Admbook versi0n <?=$constant['version']?></td>
				</tr>
				</table>
			</td>
		</tr>
		</table>
		<br/>
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td bgcolor="<?=$constant['border-color']?>">
				<table width="100%" border="0" cellpadding="2" cellspacing="1">
				<tr>
					<td bgcolor="<?=$constant['header-background-color']?>" align="center" class="headertext"><b>Lost password?</b></td>
				</tr>
				</table>
			</td>
		</tr>
		</table>
		<br/>
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td align="right">
				<div><a href="readme-ru.html" class="link"><b>read this help (ru)</b></a></div>
				<div><a href="readme-en.html" class="link"><b>read this help (en)</b></a></div>
				<div><a href="http://faq.saterenko.ru/" class="link"><b>read this faq (ru)</b></a></div>
			</td>
		</tr>
		</table>
	</td>
</tr>
<tr>
	<td align="center" class="text">
		<table border="0" cellpadding="2" cellspacing="0">
<?php
	if ($send && $error == "")
	{
?>
		<tr>
			<td class="text">Password was send to e-mail, <a href="user-login.php?currentLogin=<?=$currentLogin?>">login</a> please.</td>
		</tr>
<?php
	}
	else
	{
		if ($error != "")
		{
?>
		<tr>
			<td colspan="5" class="text">
				<b>Detect following errors:</b><br/>
				<span id="error"><?=$error?></span>
				</div>
				<br/>
			</td>
		</tr>
<?php
		}
?>
		<tr>
			<td align="center"><img src="img/name.gif" width="11" height="14" border="0" alt="Login"/></td>
			<td><img src="img/sp.gif" width="5" height="1"/></td>
			<td class="text"><span class="login">Login:</span></td>
			<td><img src="img/sp.gif" width="5" height="1"/></td>			
			<td><input type="text" name="currentLogin" value="<?=$currentLogin?>" maxlength="30" size="15" class="field"/></td>
		</tr>
		<tr>
		<tr>
			<td align="center"><img src="img/mail.gif" width="18" height="15" border="0" alt="e-mail"/></td>
			<td><img src="img/sp.gif" width="5" height="1"/></td>
			<td class="text"><span class="email">e-mail:</span></td>
			<td><img src="img/sp.gif" width="5" height="1"/></td>			
			<td><input type="text" name="currentMail" value="<?=$currentMail?>" maxlength="128" size="15" class="field"/></td>
		</tr>
		<tr>
			<td colspan="5" align="right"><input type="button" value="back" class="halfbutton" onClick="javascript:window.location.href='index.php?page=<?=$page?>'"/><input type="submit" value="send password" class="halfbutton"/></td>
		</tr>
<?php
	}
?>
		</table>
	</td>
</tr>
<tr>
	<td valign="bottom" align="right" height="1" class="text">
		<br/>
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td width="50%" bgcolor="<?=$constant['header-background-color']?>" class="headertext" align="center"><span class="text">&copy;&nbsp;</span>trent&nbsp;<a href="http://www.low.ru/dev/guestbook/" class="text" target="_top">Download this guestbook</a>&nbsp;</td>
			<td width="50%" bgcolor="<?=$constant['header-background-color']?>" class="headertext" align="center"><span class="text">&nbsp;&nbsp;&nbsp;</span><a href="http://www.mylov.ru" onclick="location.href='http://partner.mylov.ru/link.phtml?pid=10359084&lid=553';return false;" class="link" target="_top">Çíàêîìñòâà è îáùåíèå</a>&nbsp;</td>
		</tr>
		</table>
	</td>
</tr>
</table>
</form>
</body>
</html>
Return current item: Admbook