Location: PHPKode > projects > JobAppr > Jobappr-1.4/admin/reset.php
<?php
session_start();
if(isset($_SESSION['password'])){
	header("Location: dashboard.php");
	exit();
}
require_once('../includes/functions.php');
require_once('inc/admin-functions.php');

if(isset($_POST['submit'])) {
	
	$username = clean($_POST['email']);
	$sql="SELECT user_id FROM ". TB_USERS ." WHERE email='". $username ."'";
	$result=mysql_query($sql);
	$count=mysql_num_rows($result);
	
	if($count != 1){
		$error = "This email address does not have an account";
	} else {
		$success = "This email address exists";
		while ($row = mysql_fetch_assoc($result)) {
			$user_id = $row['user_id'];
		}
		$password_plain = createRandomPassword();
		$password = phash($password_plain);
		$update = "UPDATE ". TB_USERS ."
	  		SET password='".$password."'
	  		WHERE user_id='".$user_id."'
			";
		$status = mysql_query($update);
		
		if ($status) {
			sendmail($username,'Password Reset', 'Your new control panel password is: '. $password_plain);
			$success = "Successful password reset, please check your email.";
		} else {
			$error = 'Uh oh, the database connection failed'. mysql_error();
		}
	}
}

?>
<?php get_template('header', 'Reset Password'); ?>
	
	<div id="main">
		<?php display_messages(); ?>

		<h1>Reset Password</h1>
	
		<form id="reset" method="post" action="<?php echo get_filename(); ?>" >
			<table>
				<tr>
					<td class="label" ><label for="email">Email Address</label></td><td><input type="text" class="text" name="email" id="email" /></td>
				</tr>
				<tr>
					<td colspan="2"><input type="submit" class="submit" name="submit" value="Reset Password" /></td>
				</tr>
			</table>
			
		</form>
		<p class="hint" ><a href="./">Login</a></p>
			
	</div>
	
	
<?php get_template('footer'); ?>
Return current item: JobAppr