Location: PHPKode > projects > Mozart > Mozart-0.0.4/chgpass.php
<?
// called from: index.php
// description: allows user to change password
//
include("connect.inc");
include("reqlogin.inc");
include("userprefs.inc");

$Message = "Please enter your userid, password and your new password";

if ($submit) {
//	salt is used for the crypt function
	$salt = "mz";

//	get the password associated with the given system_id
	$CheckPassSQL = "SELECT first, password FROM users WHERE system_id = '$SysID'";
	$CheckPasswd  = mysql_query($CheckPassSQL);
	$CheckPass    = mysql_fetch_array($CheckPasswd);

//	if $CheckPass is empty, then the given system_id doesn't exist
	if (!($CheckPass)) {
		$Message = "Invalid System ID";
	}

//	encrypt the provided password
	$EncryptPass = crypt($Password, $salt);

//	if the password retrieved doesn't match the encrypted password provided, exit
	if (!($CheckPass["password"] == $EncryptPass)) {
		$Message = "Invalid Password";
	}
	elseif (($NewPass != $ConfPass)) {
		$Message = "New Password and Confirmation do not match";
	}
	elseif (!($NewPass)) {
		$Message = "Please enter new password";
	}
	else {
//	encrypt the new password
		$EncryptNew = crypt($NewPass, $salt);
		$UpdPassSQL = "UPDATE users SET password = '$EncryptNew' WHERE system_id = '$SysID'";
		$UpdPass = mysql_query($UpdPassSQL);
		$errno   = mysql_errno($db);
		$error   = mysql_error($db);
		if ($errno == 0) {
		   $Message = "Password Updated Successfully. Please log in.";
                   include("login.php");
		}
		else {
		   $Message = "Error $errno: $error";
		} 
	}
}
?>
<html>
<title>Mozart: Change Password</title>
<body bgcolor=<? echo $bgcolor ?> text=<? echo $txtcolor ?>>
<center>
<? 
include("links.inc");
print ("<font color=red>$Message</font>"); 
?>
<table border=1 cellspacing=0 cellpadding=0>
<form action="chgpass.php" method="post">
<tr>
<tr><td>System ID:</td><td><input type="text" name=SysID value=<? echo $SysID ?>></td></tr>
<tr><td>Password:</td><td><input type="password" name=Password value=<? echo $Password ?>></td></tr>
<tr><td>New Password:</td><td><input type="password" name=NewPass></td></tr>
<tr><td>Confirm:</td><td><input type="password" name=ConfPass></td></tr>
<tr><td><input type="submit" name="submit" value="Change Password"></td></tr>
</form>
</table>
</center>
<?
include("links.inc");
?>
</body>
</html>
Return current item: Mozart