Advertisement
Guest User

Untitled

a guest
May 17th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.89 KB | None | 0 0
  1. <?php
  2. //%%%%%%%%%  THOMAS EDIT - MY CLASS #############
  3. class CreateSession
  4. {
  5. var $itoa64;
  6.         // FUNCTION crypt_private
  7.         function crypt_private($password, $setting)
  8.         {
  9.             $output = '*0';
  10.             if (substr($setting, 0, 2) == $output)
  11.                 $output = '*1';
  12.  
  13.             if (substr($setting, 0, 3) != '$P$')
  14.                 return $output;
  15.  
  16.             $count_log2 = strpos($this->itoa64, $setting[3]);
  17.             if ($count_log2 < 7 || $count_log2 > 30)
  18.                 return $output;
  19.  
  20.             $count = 1 << $count_log2;
  21.  
  22.             $salt = substr($setting, 4, 8);
  23.             if (strlen($salt) != 8)
  24.                 return $output;
  25.  
  26.             // We're kind of forced to use MD5 here since it's the only
  27.             // cryptographic primitive available in all versions of PHP
  28.             // currently in use.  To implement our own low-level crypto
  29.             // in PHP would result in much worse performance and
  30.             // consequently in lower iteration counts and hashes that are
  31.             // quicker to crack (by non-PHP code).
  32.             if (PHP_VERSION >= '5') {
  33.                 $hash = md5($salt . $password, TRUE);
  34.                 do {
  35.                     $hash = md5($hash . $password, TRUE);
  36.                 } while (--$count);
  37.             } else {
  38.                 $hash = pack('H*', md5($salt . $password));
  39.                 do {
  40.                     $hash = pack('H*', md5($hash . $password));
  41.                 } while (--$count);
  42.             }
  43.  
  44.             $output = substr($setting, 0, 12);
  45.             $output .= $this->encode64($hash, 16);
  46.  
  47.             return $output;
  48.         }
  49.         //FUNCTION encode64()
  50.         function encode64($input, $count)
  51.     {
  52.     $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  53.    
  54.         $output = '';
  55.         $i = 0;
  56.         do {
  57.             $value = ord($input[$i++]);
  58.             $output .= $this->itoa64[$value & 0x3f];
  59.             if ($i < $count)
  60.                 $value |= ord($input[$i]) << 8;
  61.             $output .= $this->itoa64[($value >> 6) & 0x3f];
  62.             if ($i++ >= $count)
  63.                 break;
  64.             if ($i < $count)
  65.                 $value |= ord($input[$i]) << 16;
  66.             $output .= $this->itoa64[($value >> 12) & 0x3f];
  67.             if ($i++ >= $count)
  68.                 break;
  69.             $output .= $this->itoa64[($value >> 18) & 0x3f];
  70.         } while ($i < $count);
  71.  
  72.         return $output;
  73.     }
  74.         // FUNCTION CheckPassword
  75.         function CheckPassword($password, $stored_hash)
  76.         {
  77.        
  78.             $hash = $this->crypt_private($password, $stored_hash);
  79.             if ($hash[0] == '*'){
  80.                 $hash = crypt($password, $stored_hash);
  81.  
  82.             echo $hash,'   ',$stored_hash;
  83.             return $hash == $stored_hash;//RETURNS BOOLEAN 'true' or 'false'
  84.             }
  85.            
  86.            
  87.            
  88.         }
  89.        
  90.         // Check the password and then sign in
  91.         function checkpassword2()
  92.         {
  93.        
  94.         $user = $_POST['username'];
  95.         $post_password = $_POST['password'];
  96.             $mysqli = new mysqli("localhost","x","thispassword","pisk");
  97.             $query = "SELECT password FROM member WHERE username=?";
  98.             $sth = $mysqli->prepare($query);
  99.             $sth->bind_param("s",$user);
  100.             $sth->execute();
  101.             $sth->bind_result($Password);
  102.             $sth->fetch();
  103.                    
  104.             if($this->CheckPassword($post_password, $Password))
  105.             {
  106.             echo "OK OK OK";}
  107.             //echo $this->CheckPassword();
  108.             }
  109.            
  110.        
  111.         //return $UserID;
  112.     }
  113.  
  114.  
  115. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement