PHP account password Hashpassword encryption method hack code instance

Source: Internet
Author: User
PHP Account password Hashpassword encryption method hack code instance

Itoa64 = './0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz ';        if ($iteration _count_log2 < 4 | | $iteration _count_log2 >) $iteration _count_log2 = 8;        $this->iteration_count_log2 = $iteration _count_log2;        $this->portable_hashes = $portable _hashes;        $this->random_state = Microtime ();    if (function_exists (' getmypid ')) $this->random_state. = Getmypid ();        } function Get_random_bytes ($count) {$output = '; if (is_readable ('/dev/urandom ') && ($fh = @fopen ('/dev/urandom ', ' RB ')) {$OUTPU            t = fread ($FH, $count);        Fclose ($FH);            } if (strlen ($output) < $count) {$output = '; for ($i = 0; $i < $count; $i + = +) {$this->random_state = MD5 (Microtime (). $this->ra                Ndom_state); $output. = Pack (' h* ', MD5 ($this->random_state));        } $output = substr ($output, 0, $count);    } return $output;        } function Encode64 ($input, $count) {$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 >>) & 0x3f];            if ($i + + >= $count) break;        $output. = $this->itoa64[($value >>) & 0x3f];        } while ($i < $count);    return $output;        } function Gensalt_private ($input) {$output = ' $P $ ';       $output. = $this->itoa64[min ($this->iteration_count_log2 +                 ((php_version >= ' 5 ')? 5:3), 30)];        $output. = $this->encode64 ($input, 6);    return $output;        } function Crypt_private ($password, $setting) {$output = ' *0 ';        if (substr ($setting, 0, 2) = = $output) $output = ' * * ';        $id = substr ($setting, 0, 3); # We Use "$P $", PhpBB3 uses "$H $" for the same thing if ($id! = ' $P $ ' && $id! = ' $H $ ') return $o        Utput;        $count _log2 = Strpos ($this->itoa64, $setting [3]);        if ($count _log2 < 7 | | $count _log2 >) 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 P  HP # currently in use. To implement we own low-level crypto # in PHP would result in much worse performance and #Consequently in lower iteration counts and hashes that is # 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 gensalt_extended ($input) {$count _log2 = min ($this->iteration_count_log2 + 8, 24);         # This should was odd to not reveal weak DES keys, and the # Maximum valid value are (2**24-1) which is odd anyway.        $count = (1 << $count _log2)-1;        $output = ' _ ';        $output. = $this->itoa64[$count & 0x3f]; $oUtput. = $this->itoa64[($count >> 6) & 0x3f];        $output. = $this->itoa64[($count >>) & 0x3f];        $output. = $this->itoa64[($count >>) & 0x3f];        $output. = $this->encode64 ($input, 3);    return $output; } function Gensalt_blowfish ($input) {# This one needs to use a different order of characters and a #        Different encoding scheme from the one in Encode64 () above.  # We Care because the last character in our encoded string would # only represent 2 bits. While known implementations of # Bcrypt would happily accept and correct a salt string which # has the 4        Unused bits set to Non-zero, we don't want to take # chances and we also does not want to waste an additional byte        # of Entropy.        $itoa = './abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789 ';        $output = ' $2a$ '; $output. = Chr (ord (' 0 ') + $this-&GT;ITERATION_COUNT_LOG2/10);        $output. = Chr (ord (' 0 ') + $this->iteration_count_log2% 10);        $output. = ' $ ';        $i = 0;            do {$c 1 = ord ($input [$i + +]);            $output. = $itoa 64[$c 1 >> 2];            $c 1 = ($c 1 & 0x03) << 4;                if ($i >=) {$output. = $itoa 64[$c 1];            Break            } $c 2 = Ord ($input [$i + +]);            $c 1 |= $c 2 >> 4;            $output. = $itoa 64[$c 1];            $c 1 = ($c 2 & 0x0f) << 2;            $c 2 = Ord ($input [$i + +]);            $c 1 |= $c 2 >> 6;            $output. = $itoa 64[$c 1];        $output. = $itoa 64[$c 2 & 0x3f];        } while (1);    return $output;        } function Hashpassword ($password) {$random = '; if (crypt_blowfish = = 1 && $this->portable_hashes) {$random = $this->get_random_bytes (16            );    $hash = Crypt ($password, $this->gensalt_blowfish ($random));        if (strlen ($hash) = =) return $hash;                if (crypt_ext_des = = 1 &&! $this->portable_hashes) {if (strlen ($random) < 3)            $random = $this->get_random_bytes (3);            $hash = Crypt ($password, $this->gensalt_extended ($random));        if (strlen ($hash) = =) return $hash;        } if (strlen ($random) < 6) $random = $this->get_random_bytes (6);        $hash = $this->crypt_private ($password, $this->gensalt_private ($random));        if (strlen ($hash) = =) return $hash; # returning ' * ' On error was safe here, but would _not_ was safe # in a crypt (3)-like function used _both_ for genera        Ting new # hashes and for validating passwords against existing hashes.    Return ' * ';         } function Checkpassword ($password, $stored _hash) {$hash = $this->crypt_private ($password, $stored _hash); if ($hash [0] = = '* ') $hash = Crypt ($password, $stored _hash);    return $hash = = $stored _hash;    }}//demo Test ok$ps = new PasswordHash (); function Getpasslines ($file) {global $arrayCount;    Global $arrayPassList;  if (file_exists ($file) && is_readable ($file)) {if (! $fp = fopen ($file, ' R ')) {return        False            } else//read Data {$loop = true;                while ($loop) {$loop =!feof ($FP);                    if ($loop) {$stringLine =fgets ($fp, 50);                    $arrayPassList [$arrayCount] =trim ($stringLine);                $arrayCount + +;                } else {break;            }} fclose ($FP);        return true;    }} else {return false; }} $arrayPasswordHashValue = Array (' $2y$10$l2*************************************** '); $bRet = Getpasslines (' Dic.txt '); if ($bRet) {GloBal $arrayCount;    Global $arrayPassList;        for ($rows = 0; $rows < count ($arrayPasswordHashValue); $rows + +) {echo "row:{$rows}\n"; for ($columns = 0; $columns < $arrayCount; $columns + +) {$resultFind = $ps->checkpassword ($arrayPa            sslist[$columns], $arrayPasswordHashValue [$rows]); if ($resultFind = = 1) {echo "{$rows}:{$columns}".            Success\n "; }}}}?>

The above describes the PHP account password Hashpassword encryption method to crack code examples, including the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.