Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //%%%%%%%%% THOMAS EDIT - MY CLASS #############
- class CreateSession
- {
- var $itoa64;
- // FUNCTION crypt_private
- function crypt_private($password, $setting)
- {
- $output = '*0';
- if (substr($setting, 0, 2) == $output)
- $output = '*1';
- if (substr($setting, 0, 3) != '$P$')
- return $output;
- $count_log2 = strpos($this->itoa64, $setting[3]);
- if ($count_log2 < 7 || $count_log2 > 30)
- return $output;
- $count = 1 << $count_log2;
- $salt = substr($setting, 4, 8);
- if (strlen($salt) != 8)
- return $output;
- // We're kind of forced to use MD5 here since it's the only
- // cryptographic primitive available in all versions of PHP
- // currently in use. To implement our own low-level crypto
- // in PHP would result in much worse performance and
- // consequently in lower iteration counts and hashes that are
- // quicker to crack (by non-PHP code).
- if (PHP_VERSION >= '5') {
- $hash = md5($salt . $password, TRUE);
- do {
- $hash = md5($hash . $password, TRUE);
- } while (--$count);
- } else {
- $hash = pack('H*', md5($salt . $password));
- do {
- $hash = pack('H*', md5($hash . $password));
- } while (--$count);
- }
- $output = substr($setting, 0, 12);
- $output .= $this->encode64($hash, 16);
- return $output;
- }
- //FUNCTION encode64()
- function encode64($input, $count)
- {
- $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
- $output = '';
- $i = 0;
- do {
- $value = ord($input[$i++]);
- $output .= $this->itoa64[$value & 0x3f];
- if ($i < $count)
- $value |= ord($input[$i]) << 8;
- $output .= $this->itoa64[($value >> 6) & 0x3f];
- if ($i++ >= $count)
- break;
- if ($i < $count)
- $value |= ord($input[$i]) << 16;
- $output .= $this->itoa64[($value >> 12) & 0x3f];
- if ($i++ >= $count)
- break;
- $output .= $this->itoa64[($value >> 18) & 0x3f];
- } while ($i < $count);
- return $output;
- }
- // FUNCTION CheckPassword
- function CheckPassword($password, $stored_hash)
- {
- $hash = $this->crypt_private($password, $stored_hash);
- if ($hash[0] == '*'){
- $hash = crypt($password, $stored_hash);
- echo $hash,' ',$stored_hash;
- return $hash == $stored_hash;//RETURNS BOOLEAN 'true' or 'false'
- }
- }
- // Check the password and then sign in
- function checkpassword2()
- {
- $user = $_POST['username'];
- $post_password = $_POST['password'];
- $mysqli = new mysqli("localhost","x","thispassword","pisk");
- $query = "SELECT password FROM member WHERE username=?";
- $sth = $mysqli->prepare($query);
- $sth->bind_param("s",$user);
- $sth->execute();
- $sth->bind_result($Password);
- $sth->fetch();
- if($this->CheckPassword($post_password, $Password))
- {
- echo "OK OK OK";}
- //echo $this->CheckPassword();
- }
- //return $UserID;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement