Managment page has better look and feel.
[Assignment-Trapper.git] / auth.php
blob7ee9c030e0980be2a29beee5e53b26053a825d5e
1 <?php
3 include_once("conn.php");
5 /* verify username and password - do not pass if incorrect */
6 if(!isset($_COOKIE["username"])) { include("login.php"); exit; }
7 if(!isset($_COOKIE["password"])) { include("login.php"); exit; }
9 $_COOKIE["username"] = mysql_real_escape_string($_COOKIE["username"]);
10 $_COOKIE["password"] = mysql_real_escape_string($_COOKIE["password"]);
12 $sql = "select count(*), user_id, role, name, first_login, email from users where attempts < 100 and email='". $_COOKIE["username"]. "' and password=SHA(\"".$_COOKIE["password"]."\")";
14 //echo $sql;
16 $result = mysql_query($sql);
18 if (!$result) { die("SQL ERROR: Get Cred"); }
20 $row = mysql_fetch_row($result);
22 /* if we don't get a good login, send username and password form and exit */
23 if($row[0] <= 0) { // bad login
25 // increment tries for user - this will lock them out
26 $sql = "update users set attempts = attempts + 1 where email='". $_COOKIE["username"]."'";
28 $result = mysql_query($sql);
30 //echo $sql;
32 echo "Incorrect Username or Password.";
33 include("login.php");
34 exit;
35 } else { // good login
37 // set attempts to zero
38 $sql = "update users set attempts = 0 where email='". $_COOKIE["username"]."'";
40 $result = mysql_query($sql);
43 /* set global var with user id and email address - shown on pages and used in URL's */
44 $user_id = $row[1];
45 $role = $row[2];
46 $user_name = $row[3];
47 $first_login = $row[4];
48 $user_email = $row[5];
50 /* if this is your first login, you MUST change password */
51 if($first_login == 1) { include("password_change.php"); exit; }
53 if($user_id == NULL) { die("User ID Not Set For This User. Contact Technical Support."); }