Advertisement
Guest User

Untitled

a guest
May 8th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.19 KB | None | 0 0
  1. <?php /* login.php - marknt15 */
  2.  
  3.     // start session events
  4.     session_name("MARK_SESSID");
  5.     session_start();
  6.     define("IN_MARK", true);
  7.     $root_path = './';
  8.     $header_main_php = $root_path . 'main.php';
  9.  
  10.     include "./db/db_functions.obj";
  11.     // database connection
  12.     $db = new DB();
  13.     $db->connect();
  14.  
  15.     // check for username and password
  16.  
  17.     if(($_POST['username'])||($_POST['password']))
  18.     {
  19.  
  20.         if(empty($_POST['username'])){
  21.             $u = FALSE;
  22.             $_SESSION['logged_in'] = FALSE;
  23.             header( "Location: ./index.php?access=no_username" );
  24.         }
  25.         else { $u = $_POST['username']; }
  26.    
  27.         if(empty($_POST['password'])){
  28.             $p = FALSE;
  29.             $_SESSION['logged_in'] = FALSE;
  30.             header( "Location: ./index.php?access=no_password" );
  31.         }
  32.         else { $p = $_POST['password']; }
  33.     } else {
  34.         $u = FALSE;
  35.         $p = FALSE;
  36.         $_SESSION['logged_in'] = FALSE;
  37.         header( "Location: ./index.php?access=denied" );
  38.     }
  39.  
  40.     // password encryption
  41.     $password_sha1 = SHA1($p);
  42.     $password_md5 = MD5($p);
  43.     $password_hash = $password_sha1 . $password_md5;
  44.  
  45.     $password_sha1_2 = SHA1($password_hash);
  46.     $password_md5_2 = MD5($password_hash);
  47.     $password_hash_2 = $password_sha1_2 . $password_md5_2;
  48.  
  49.     $password_hash_final = $password_hash_2;
  50.    
  51.     // if the username and password is both set
  52.     if(($u) && ($p)) {
  53.  
  54.         $query= "select a.EmpNo, a.Username, a.Password, b.First_Name, b.Middle_Name, b.Last_Name, a.Privilege,
  55.                 a.Last_Login
  56.                 from user_tbl a, employee_tbl b
  57.                 where a.Username = '$u' and a.Password = '$p' and a.EmpNo = b.EmpNo";
  58.  
  59.         $result = mysql_query($query) or die (mysql_error());
  60.         if(mysql_num_rows($result) == 0){ // no results found for $u and $p
  61.  
  62.             $_SESSION['logged_in'] = FALSE;
  63.             // check for username if username exists
  64.             $select_username="select EmpNo from user_tbl where Username = '$u'";
  65.             $result_username = mysql_query($select_username) or die (mysql_error());
  66.            
  67.             if(mysql_num_rows($result_username) == 0){
  68.                 // login error: no username in database
  69.                 header("Location: ./index.php?access=user_error&username=$u");
  70.             } else {
  71.                 // login error: incorrect password for username
  72.                 header("Location: ./index.php?access=pass_error&username=$u");
  73.             }
  74.             mysql_free_result($result_username);
  75.         } else {
  76.             /*
  77.                 if ($_POST['option'] == 'installation'){ $system_option = "installation"; }
  78.                 else if ($_POST['option'] == 'techsup') { $system_option = "techsup"; }
  79.                 else if ($_POST['option'] == 'site') { $system_option = "site"; }
  80.                 else if ($_POST['option'] == '') { header("Location: index.php?access=no_option"); }
  81.             */ 
  82.                
  83.                 switch ($_POST['option']) {
  84.                     case "installation":
  85.                         $system_option = "installation";
  86.                         break;
  87.                     case "techsup":
  88.                         $system_option = "techsup";
  89.                         break;
  90.                     case "site":
  91.                         $system_option = "site";
  92.                         break;
  93.                     case "":
  94.                         header("Location: index.php?access=no_option");
  95.                         break;
  96.                 }
  97.                
  98.                
  99.                
  100.             while($row = mysql_fetch_array($result, MYSQL_BOTH)){
  101.                 $_SESSION['Username'] = $u;
  102.                 $_SESSION['Password'] = $password_hash_final;  
  103.                 $_SESSION['EmployeeID'] = $row[0];
  104.                 $_SESSION['PrivilegeID'] = $row[6];
  105.                 $_SESSION['FullName'] = $row[3] ." ". $row[4] ." ". $row[5];
  106.                 $_SESSION['logged_in'] = TRUE;
  107.                 $_SESSION['last_login'] = $row[7];
  108.                 $_SESSION['system'] = $system_option;
  109.                
  110.                 $check_last_login = "select Last_Login from user_tbl where Username = '$u'" ;
  111.                 $result_check = mysql_query($check_last_login) or die(mysql_error());
  112.                
  113.                 $numrows_check = mysql_num_rows($result_check);
  114.                 while ($line = mysql_fetch_array($result_check, MYSQL_BOTH)){
  115.                   $last_login_x = $line['Last_Login'];
  116.                 }
  117.                
  118.                 $timestamp = date("Y-m-d");            
  119.                
  120.                 //if($last_login_x == ''){ // if last login of user is NULL, update Last_Login
  121.                 if(!$last_login_x){ // if last login of user is NULL, update Last_Login
  122.                     $insert="update user_tbl set Last_Login = '$timestamp' where Username = '$u'";
  123.                     $result_insert = mysql_query($insert) or die(mysql_error());
  124.                        
  125.                 }
  126.                 else{ // update
  127.                     $update="update user_tbl set Last_Login = '$timestamp' where Username = '$u'";
  128.                     $result_update = mysql_query($update) or die(mysql_error());
  129.                 }  
  130.                
  131.                 // put condition here sa header techsup or installation
  132.                 if ($_POST['option'] == 'installation'){
  133.                     //header("Location: main_install.php");
  134.                     header("Location: progress_bar2.php");
  135.                 } else if ($_POST['option'] == 'techsup') {
  136.                     //header("Location: main.php");
  137.                     header("Location: progress_bar.php");
  138.                 } else if ($_POST['option'] == 'site') {
  139.                     //header("Location: main_site.php");
  140.                     header("Location: progress_bar3.php");
  141.                 } else if ($_POST['option'] == '') {
  142.                     header("Location: index.php?access=no_option");
  143.                 }
  144.                     // if username and password is valid, go to main page
  145.                     //header("Location: main.php");
  146.             }
  147.         }
  148.         mysql_free_result($result);
  149.    }
  150.  
  151.     // unset php variables
  152.     unset($u);
  153.     unset($p);
  154.     unset($password_sha1);
  155.     unset($password_md5);
  156.     unset($password_hash);
  157.     unset($password_sha1_2);
  158.     unset($password_md5_2);
  159.     unset($password_hash_2);
  160.     unset($password_hash_final);
  161.     $db->disconnect();
  162.  
  163.  
  164. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement