<?
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# DataDivisions, Build 1.0, 12/11/2003 #
# FileName: funcLogin.php #
# File Description: #
# Provides functions required for a user to login to application (back- #
# end, middle and front-end) #
# #
# +-----------------------------------------------------------------------+ #
# | DataDivisions - Website Statistic Visualization Software | #
# | Copyright (c) 2003, Brian Willison | #
# +-----------------------------------------------------------------------+ #
# | The contents of this file are subject to the GNU General Public | #
# | License version 2 (June 1991). This file and all its contents (incl. | #
# | functions, methods, etc.) are free for general use within any | #
# | community. This software is distributed with the intent to allow | #
# | developers the opportunity to copy, manipulate and revamp this | #
# | application in part or whole for best use cases. | #
# | | #
# | This software is distributed "AS-IS" with no warranties of any kind | #
# | either expressed or implied. | #
# | | #
# | Please refer to the GPL license document for more information: | #
# | (_docs/gplLicense.pdf) | #
# +-----------------------------------------------------------------------+ #
# | Developer, Designer, Initial Creator: | #
# | Brian Willison (hide@address.com) | #
# +-----------------------------------------------------------------------+ #
# | Initial Download Reference: | #
# | http://datadivisions.sourceforge.net | #
# +-----------------------------------------------------------------------+ #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Function: Check Login Credentials
function checkLoginForm($_POST) {
// Check If User Posted Any Info
if ($_POST['username'] == "" || $_POST['password'] == "") { // username and password submitted blank
return "blankSubmit";
} else {
// Get All Db Users Info
$dbOpen = dbConnect();
$query = "SELECT * FROM ".dbTableUsers;
$result = mysql_query($query);
$numRows = mysql_num_rows($result);
// Check For Submitted User Info
for ($i=0; $i<$numRows; $i++) {
$array = mysql_fetch_array($result);
if ($array[0] == $_POST['username']) { // username found, so check password
if ($array[1] == $_POST['password']) { // check password
if (isset($_POST['rememberLogin']))
setUserLoginCookie($_POST['username']); // set username cookie with checkbox marked
dbClose($dbOpen);
return $_POST['username']; // password is correct
} else {
dbClose($dbOpen);
return "passwordFailed"; // password is NOT correct
}
}
}
dbClose($dbOpen);
return "noUserInDb"; // no user in db
}
}
// Function: Generate Login Form
function genLoginForm($errorCheck) {
global $_POST;
genAppSmHeader(pageName); // generate application header
?>
<tr>
<td></td>
<td valign="top" colspan="3">
<p class="header">New user? Please click <a href="<?=registerPage?>">here</a> to set up your account.
<p>If your session has timed out or you would like to re-login to <?=appNameShort?>, please enter your login
credentials below.
</td>
<td></td>
</tr>
<tr>
<td valign="top" colspan="5"><?writeSpacer(1,10);?></td>
</tr>
<?
if ($errorCheck != 0) {
printf("\t<tr><td></td><td valign=\"top\" colspan=\"3\"><p class=\"error\">%s</td><td></td></tr>",genErrorMsg($errorCheck));
}
?>
<tr>
<td valign="top" colspan="5"><?writeSpacer(1,10);?></td>
</tr>
<tr>
<form name="login" method="post" action="<?=phpSelf?>">
<td></td>
<td><p align="right">Username:</td>
<td></td>
<td><p><input type="text" name="username" size="25" maxlength="25" value="<?if(isset($_POST['username'])){echo$_POST['username'];}?>"></td>
<td></td>
</tr>
<tr>
<td></td>
<td><p align="right">Password:</td>
<td></td>
<td><p><input type="password" name="password" size="25" maxlength="10"></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td valign="top"><p class="small"><input type="checkbox" name="rememberLogin" checked> Remember My Login</td>
<td></td>
</tr>
<tr>
<td valign="top" colspan="5"><?writeSpacer(1,10);?></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td valign="top"><input type="submit" name="submit" value="Submit" class="btnSubmit"></td>
<td></td>
</form>
</tr>
<tr>
<td valign="top" colspan="5"><?writeSpacer(1,15);?></td>
</tr>
<?
genAppSmFooter(pageName); // generate application footer
}
?>