SHARE
TWEET

Untitled

a guest May 22nd, 2017 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     // Error management
  3.     ini_set('display_errors', 1);
  4.     error_reporting(E_ALL | E_STRICT);
  5.    
  6.     require('includes/connection.php');
  7.     require('includes/cookie.php');
  8.    
  9.     define('TITLE', 'Login');
  10.     require('template/header.php');
  11.    
  12.    
  13.     if (!loggedin()) { // Not logged in
  14.    
  15.         if ( isset($_POST['submitted']) ) {
  16.        
  17.             $username = trim($_POST['username']);
  18.             $password = sha1(trim($_POST['password']));
  19.            
  20.             $query = "SELECT password FROM users WHERE username='$username'";
  21.             $r = mysql_query($query);
  22.            
  23.             if (mysql_num_rows($r) == 1) { // Username is valid
  24.            
  25.                 if (mysql_result($r, 0) == $password) { // Password is valid
  26.                
  27.                     $cid = sha1(microtime(true));
  28.                     mysql_query("UPDATE users SET cid='$cid' WHERE username='$username'");
  29.                    
  30.                     $_SESSION['cid'] = $cid;
  31.                     setcookie('cid', $cid, time()+1209600);
  32.                     $loggedin = true;
  33.                    
  34.                 } else { // Password is invalid
  35.                     $problem = 'Invalid password';
  36.                 }
  37.                
  38.             } else { // Username is invalid
  39.                 $problem = 'Invalid username';
  40.             }
  41.            
  42.             if (isset($problem)) { // Username or password is invalid
  43.                 echo '<p class="error">' . $problem . '</p>';
  44.             }
  45.            
  46.         }
  47.        
  48.         if (isset($loggedin)) {
  49.             echo '<div id="formdiv"><br /><br /><br /><p style="font-size: 120%; text-align: center;">Login successful</p><br /><br /><br /></div>';
  50.         } else {
  51. ?>
  52.  
  53. <form action="login.php" method="post">
  54.     <p>
  55.     <label for="username">Username:</label>
  56.     <input type="text" name="username" size="30" />
  57.     </p>
  58.    
  59.     <p>
  60.     <label for="password">Password:</label>
  61.     <input type="password" name="password" size="30" />
  62.     </p>
  63.    
  64.     <input type="submit" name="submit" value="Login" />
  65.     <input type="hidden" name="submitted" value="true" />
  66. </form>
  67.  
  68. <?php
  69.         }
  70.        
  71.     } else { // Already logged in
  72.         echo '<div id="formdiv"><br /><br /><br /><p class="error" style="font-size: 130%; text-align: center;">You are already logged in</p><br /><br /><br /></div>';
  73.     }
  74.    
  75.     require('template/footer.php');
  76. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top