-
+ 198E6C088E9F88AD3A63ABE6F3EE636630A728A0FDC429C250F6C32364E65FE0ED3CA4121733B83F8AF760CD9772513EB686BED9B71CC285A9A664A639A2CF99mp-wp/wp-includes/class-phpass.php(0 . 0)(1 . 258)
76395 <?php
76396 /**
76397 * Portable PHP password hashing framework.
76398 * @package phpass
76399 * @since 2.5
76400 * @version 0.1
76401 * @link http://www.openwall.com/phpass/
76402 */
76403
76404 #
76405 # Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in
76406 # the public domain.
76407 #
76408 # There's absolutely no warranty.
76409 #
76410 # Please be sure to update the Version line if you edit this file in any way.
76411 # It is suggested that you leave the main version number intact, but indicate
76412 # your project name (after the slash) and add your own revision information.
76413 #
76414 # Please do not change the "private" password hashing method implemented in
76415 # here, thereby making your hashes incompatible. However, if you must, please
76416 # change the hash type identifier (the "$P$") to something different.
76417 #
76418 # Obviously, since this code is in the public domain, the above are not
76419 # requirements (there can be none), but merely suggestions.
76420 #
76421
76422 /**
76423 * Portable PHP password hashing framework.
76424 *
76425 * @package phpass
76426 * @version 0.1 / genuine
76427 * @link http://www.openwall.com/phpass/
76428 * @since 2.5
76429 */
76430 class PasswordHash {
76431 var $itoa64;
76432 var $iteration_count_log2;
76433 var $portable_hashes;
76434 var $random_state;
76435
76436 function PasswordHash($iteration_count_log2, $portable_hashes)
76437 {
76438 $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
76439
76440 if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31)
76441 $iteration_count_log2 = 8;
76442 $this->iteration_count_log2 = $iteration_count_log2;
76443
76444 $this->portable_hashes = $portable_hashes;
76445
76446 $this->random_state = microtime() . (function_exists('getmypid') ? getmypid() : '') . uniqid(rand(), TRUE);
76447
76448 }
76449
76450 function get_random_bytes($count)
76451 {
76452 $output = '';
76453 if (($fh = @fopen('/dev/urandom', 'rb'))) {
76454 $output = fread($fh, $count);
76455 fclose($fh);
76456 }
76457
76458 if (strlen($output) < $count) {
76459 $output = '';
76460 for ($i = 0; $i < $count; $i += 16) {
76461 $this->random_state =
76462 md5(microtime() . $this->random_state);
76463 $output .=
76464 pack('H*', md5($this->random_state));
76465 }
76466 $output = substr($output, 0, $count);
76467 }
76468
76469 return $output;
76470 }
76471
76472 function encode64($input, $count)
76473 {
76474 $output = '';
76475 $i = 0;
76476 do {
76477 $value = ord($input[$i++]);
76478 $output .= $this->itoa64[$value & 0x3f];
76479 if ($i < $count)
76480 $value |= ord($input[$i]) << 8;
76481 $output .= $this->itoa64[($value >> 6) & 0x3f];
76482 if ($i++ >= $count)
76483 break;
76484 if ($i < $count)
76485 $value |= ord($input[$i]) << 16;
76486 $output .= $this->itoa64[($value >> 12) & 0x3f];
76487 if ($i++ >= $count)
76488 break;
76489 $output .= $this->itoa64[($value >> 18) & 0x3f];
76490 } while ($i < $count);
76491
76492 return $output;
76493 }
76494
76495 function gensalt_private($input)
76496 {
76497 $output = '$P$';
76498 $output .= $this->itoa64[min($this->iteration_count_log2 +
76499 ((PHP_VERSION >= '5') ? 5 : 3), 30)];
76500 $output .= $this->encode64($input, 6);
76501
76502 return $output;
76503 }
76504
76505 function crypt_private($password, $setting)
76506 {
76507 $output = '*0';
76508 if (substr($setting, 0, 2) == $output)
76509 $output = '*1';
76510
76511 if (substr($setting, 0, 3) != '$P$')
76512 return $output;
76513
76514 $count_log2 = strpos($this->itoa64, $setting[3]);
76515 if ($count_log2 < 7 || $count_log2 > 30)
76516 return $output;
76517
76518 $count = 1 << $count_log2;
76519
76520 $salt = substr($setting, 4, 8);
76521 if (strlen($salt) != 8)
76522 return $output;
76523
76524 # We're kind of forced to use MD5 here since it's the only
76525 # cryptographic primitive available in all versions of PHP
76526 # currently in use. To implement our own low-level crypto
76527 # in PHP would result in much worse performance and
76528 # consequently in lower iteration counts and hashes that are
76529 # quicker to crack (by non-PHP code).
76530 if (PHP_VERSION >= '5') {
76531 $hash = md5($salt . $password, TRUE);
76532 do {
76533 $hash = md5($hash . $password, TRUE);
76534 } while (--$count);
76535 } else {
76536 $hash = pack('H*', md5($salt . $password));
76537 do {
76538 $hash = pack('H*', md5($hash . $password));
76539 } while (--$count);
76540 }
76541
76542 $output = substr($setting, 0, 12);
76543 $output .= $this->encode64($hash, 16);
76544
76545 return $output;
76546 }
76547
76548 function gensalt_extended($input)
76549 {
76550 $count_log2 = min($this->iteration_count_log2 + 8, 24);
76551 # This should be odd to not reveal weak DES keys, and the
76552 # maximum valid value is (2**24 - 1) which is odd anyway.
76553 $count = (1 << $count_log2) - 1;
76554
76555 $output = '_';
76556 $output .= $this->itoa64[$count & 0x3f];
76557 $output .= $this->itoa64[($count >> 6) & 0x3f];
76558 $output .= $this->itoa64[($count >> 12) & 0x3f];
76559 $output .= $this->itoa64[($count >> 18) & 0x3f];
76560
76561 $output .= $this->encode64($input, 3);
76562
76563 return $output;
76564 }
76565
76566 function gensalt_blowfish($input)
76567 {
76568 # This one needs to use a different order of characters and a
76569 # different encoding scheme from the one in encode64() above.
76570 # We care because the last character in our encoded string will
76571 # only represent 2 bits. While two known implementations of
76572 # bcrypt will happily accept and correct a salt string which
76573 # has the 4 unused bits set to non-zero, we do not want to take
76574 # chances and we also do not want to waste an additional byte
76575 # of entropy.
76576 $itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
76577
76578 $output = '$2a$';
76579 $output .= chr(ord('0') + $this->iteration_count_log2 / 10);
76580 $output .= chr(ord('0') + $this->iteration_count_log2 % 10);
76581 $output .= '$';
76582
76583 $i = 0;
76584 do {
76585 $c1 = ord($input[$i++]);
76586 $output .= $itoa64[$c1 >> 2];
76587 $c1 = ($c1 & 0x03) << 4;
76588 if ($i >= 16) {
76589 $output .= $itoa64[$c1];
76590 break;
76591 }
76592
76593 $c2 = ord($input[$i++]);
76594 $c1 |= $c2 >> 4;
76595 $output .= $itoa64[$c1];
76596 $c1 = ($c2 & 0x0f) << 2;
76597
76598 $c2 = ord($input[$i++]);
76599 $c1 |= $c2 >> 6;
76600 $output .= $itoa64[$c1];
76601 $output .= $itoa64[$c2 & 0x3f];
76602 } while (1);
76603
76604 return $output;
76605 }
76606
76607 function HashPassword($password)
76608 {
76609 $random = '';
76610
76611 if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) {
76612 $random = $this->get_random_bytes(16);
76613 $hash =
76614 crypt($password, $this->gensalt_blowfish($random));
76615 if (strlen($hash) == 60)
76616 return $hash;
76617 }
76618
76619 if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) {
76620 if (strlen($random) < 3)
76621 $random = $this->get_random_bytes(3);
76622 $hash =
76623 crypt($password, $this->gensalt_extended($random));
76624 if (strlen($hash) == 20)
76625 return $hash;
76626 }
76627
76628 if (strlen($random) < 6)
76629 $random = $this->get_random_bytes(6);
76630 $hash =
76631 $this->crypt_private($password,
76632 $this->gensalt_private($random));
76633 if (strlen($hash) == 34)
76634 return $hash;
76635
76636 # Returning '*' on error is safe here, but would _not_ be safe
76637 # in a crypt(3)-like function used _both_ for generating new
76638 # hashes and for validating passwords against existing hashes.
76639 return '*';
76640 }
76641
76642 function CheckPassword($password, $stored_hash)
76643 {
76644 $hash = $this->crypt_private($password, $stored_hash);
76645 if ($hash[0] == '*')
76646 $hash = crypt($password, $stored_hash);
76647
76648 return $hash == $stored_hash;
76649 }
76650 }
76651
76652 ?>