Location: PHPKode > projects > Mozart > Mozart-0.0.4/login.php
// called from: reqlogin.php; index.php3
// description: user login; sets cookie file to contain the user_id, system_id and
//              encrypted password; this information is used in reqlogin.php to 
//              validate the user
// if $GoodPass is 1, then a successful system_id/password combination was given
$GoodPass = 0;
$Message  = "Please log in";

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

//	get the password associated with the given system_id
	$CheckPassSQL = "SELECT user_id, 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";
	else {
		$GoodPass = 1;
                $UserID   = $CheckPass["user_id"];
//if we haven't been given a good system_id/password combination, print the login screen and exit
if (!($GoodPass)) {
	<title>Mozart: Login</title>
        <body bgcolor="#FFFFFF" text="#000000">
	<? print("<font color=red>$Message</font>"); ?>
	<table border=1 cellspacing=0 cellpadding=0>
	<form action="login.php" method="post">
	<tr><td>System ID:</td><td><input type="text" name=SysID value=<? echo $SysID ?>></td>
	<tr><td>Password:</td><td><input type="password" name=Password value=<? echo $Password ?>></td>
	<tr><td><input type="checkbox" name=TempCookie value=<? echo $TempCookie ?>>Use Temporary Cookie</td>
	<tr><td><input type="submit" name="submit" value="Login"></td>
// if we get here, we have a valid user
// set the new cookie
if (!($TempCookie)) {
//  set the cookie for one year
        setcookie("cookie[SysID]", "$SysID", time()+1166832000, "/");
        setcookie("cookie[UserID]", "$UserID", time()+1166832000, "/");
        setcookie("cookie[Passwd]", "$EncryptPass", time()+1166832000, "/");
else {
//  set the cookie for this session only
        setcookie("cookie[SysID]", "$SysID");
        setcookie("cookie[UserID]", "$UserID");
        setcookie("cookie[Passwd]", "$Passwd");
// branch to index;
$Message = "";
// the following line is for debugging purposes only.
// phpinfo();
Return current item: Mozart