Guest User

Untitled

a guest
Apr 12th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.31 KB | None | 0 0
  1. <?php
  2.  
  3. function createsessions($username)
  4. {
  5.     $salt=uniqid(rand(), true);
  6.     setcookie('cusername',hash('sha512',$username.$salt),time()+3600);
  7.     setcookie('cid',hash('sha512',session_id(),$salt),time()+3600);
  8.     setcookie('cauth',hash('sha512','yes',$salt),time()+3600);
  9.     session_register();
  10.     $_SESSION['susername'] = hash('sha512',$username,$salt);
  11.     $_SESSION['sid'] = hash('sha512',session_id(),$salt);
  12.     $_SESSION['sauth'] = hash('sha512','yes',$salt);
  13. }
  14.  
  15. function deletesessions()
  16. {
  17.     unset($_SESSION['susername']);
  18.     unset($_SESSION['sid']);
  19.     unset($_SESSION['sauth']);
  20.     session_unset();
  21.     session_destroy();
  22.     setcookie('cusername','',time()-3600);
  23.     setcookie('cid','',time()-3600);
  24.     setcookie('cauth','',time()-3600);
  25. }
  26.  
  27. function login($username,$password) {
  28.     $username = mysql_real_escape_string( stripslashes($_POST['username']));
  29.     $password = mysql_real_escape_string( stripslashes($_POST['password']));
  30.        
  31.     $salt = '10367001714ecbe6c5f01862.28316256';
  32.     $salt2 = '10868308824ecbe6c5f01750.38838567';
  33.     $eusername = hash("sha512",$username.$salt2);
  34.     $epassword = hash("sha512",$password.$salt);
  35.    
  36.     $saltquery = mysql_query("SELECT `usernamesalt` AND `passwordsalt` FROM `users` WHERE username='".$eusername."'");
  37.         while($row = mysql_fetch_row($saltquery)) {
  38.             $usernamesalt = $row['0'];
  39.             $passwordsalt = $row['1'];
  40.     }
  41.  
  42.     $check = mysql_query("SELECT * FROM `users` WHERE username='".$eusername."' and password='".$epassword."' LIMIT 1");
  43.     $count = mysql_num_rows($check);
  44.     if($count == 1)
  45.     {
  46.     return true;
  47.     } else {
  48.     return false;
  49.     }
  50. }
  51.  
  52. function checkauth() {
  53.     if (isset($_SESSION['susername']) && isset($_SESSION['sid']) && isset($_SESSION['sauth']) && isset($_COOKIE['cusername']) && isset($_COOKIE['cid']) && isset ($_COOKIE['cauth'])) {
  54.         if ($_SESSION['sid'] && $_COOKIES['cid'] == session_id && $_SESSION['susername'] && $_COOKIE['cusername'] == $_POST['username']) {
  55.         return true;
  56.         }
  57.     }
  58.     if (login($_POST['username'],$_POST['password'])) {
  59.         createsessions($_POST['username']);
  60.         return true;
  61.     } else {
  62.         deletesessions();
  63.         return false;
  64.     }
  65. }
  66.  
  67. function loginform() {
  68.     echo "
  69.         <form method='POST' action='login.php'>
  70.         <input type='text' name='username'><br>
  71.         <input type='text' name='password'>
  72.         <input type='submit' name='login' value='Submit'>
  73.         </form>";
  74. }
  75. ?>
Add Comment
Please, Sign In to add comment