Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../var/softacul.../impressp...
File: PasswordHash.php
<?php
[0] Fix | Delete
[1] Fix | Delete
#
[2] Fix | Delete
# Portable PHP password hashing framework.
[3] Fix | Delete
#
[4] Fix | Delete
# Version 0.3 / genuine.
[5] Fix | Delete
#
[6] Fix | Delete
# Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in
[7] Fix | Delete
# the public domain. Revised in subsequent years, still public domain.
[8] Fix | Delete
#
[9] Fix | Delete
# There's absolutely no warranty.
[10] Fix | Delete
#
[11] Fix | Delete
# The homepage URL for this framework is:
[12] Fix | Delete
#
[13] Fix | Delete
# http://www.openwall.com/phpass/
[14] Fix | Delete
#
[15] Fix | Delete
# Please be sure to update the Version line if you edit this file in any way.
[16] Fix | Delete
# It is suggested that you leave the main version number intact, but indicate
[17] Fix | Delete
# your project name (after the slash) and add your own revision information.
[18] Fix | Delete
#
[19] Fix | Delete
# Please do not change the "private" password hashing method implemented in
[20] Fix | Delete
# here, thereby making your hashes incompatible. However, if you must, please
[21] Fix | Delete
# change the hash type identifier (the "$P$") to something different.
[22] Fix | Delete
#
[23] Fix | Delete
# Obviously, since this code is in the public domain, the above are not
[24] Fix | Delete
# requirements (there can be none), but merely suggestions.
[25] Fix | Delete
#
[26] Fix | Delete
class PasswordHash {
[27] Fix | Delete
var $itoa64;
[28] Fix | Delete
var $iteration_count_log2;
[29] Fix | Delete
var $portable_hashes;
[30] Fix | Delete
var $random_state;
[31] Fix | Delete
[32] Fix | Delete
function __construct($iteration_count_log2, $portable_hashes)
[33] Fix | Delete
{
[34] Fix | Delete
$this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
[35] Fix | Delete
[36] Fix | Delete
if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31)
[37] Fix | Delete
$iteration_count_log2 = 8;
[38] Fix | Delete
$this->iteration_count_log2 = $iteration_count_log2;
[39] Fix | Delete
[40] Fix | Delete
$this->portable_hashes = $portable_hashes;
[41] Fix | Delete
[42] Fix | Delete
$this->random_state = microtime();
[43] Fix | Delete
if (function_exists('getmypid'))
[44] Fix | Delete
$this->random_state .= getmypid();
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
function get_random_bytes($count)
[48] Fix | Delete
{
[49] Fix | Delete
$output = '';
[50] Fix | Delete
// throws open_basedir restriction in effect on some servers
[51] Fix | Delete
// if (is_readable('/dev/urandom') &&
[52] Fix | Delete
// ($fh = @fopen('/dev/urandom', 'rb'))) {
[53] Fix | Delete
// $output = fread($fh, $count);
[54] Fix | Delete
// fclose($fh);
[55] Fix | Delete
// }
[56] Fix | Delete
[57] Fix | Delete
if (strlen($output) < $count) {
[58] Fix | Delete
$output = '';
[59] Fix | Delete
for ($i = 0; $i < $count; $i += 16) {
[60] Fix | Delete
$this->random_state =
[61] Fix | Delete
md5(microtime() . $this->random_state);
[62] Fix | Delete
$output .=
[63] Fix | Delete
pack('H*', md5($this->random_state));
[64] Fix | Delete
}
[65] Fix | Delete
$output = substr($output, 0, $count);
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
return $output;
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
function encode64($input, $count)
[72] Fix | Delete
{
[73] Fix | Delete
$output = '';
[74] Fix | Delete
$i = 0;
[75] Fix | Delete
do {
[76] Fix | Delete
$value = ord($input[$i++]);
[77] Fix | Delete
$output .= $this->itoa64[$value & 0x3f];
[78] Fix | Delete
if ($i < $count)
[79] Fix | Delete
$value |= ord($input[$i]) << 8;
[80] Fix | Delete
$output .= $this->itoa64[($value >> 6) & 0x3f];
[81] Fix | Delete
if ($i++ >= $count)
[82] Fix | Delete
break;
[83] Fix | Delete
if ($i < $count)
[84] Fix | Delete
$value |= ord($input[$i]) << 16;
[85] Fix | Delete
$output .= $this->itoa64[($value >> 12) & 0x3f];
[86] Fix | Delete
if ($i++ >= $count)
[87] Fix | Delete
break;
[88] Fix | Delete
$output .= $this->itoa64[($value >> 18) & 0x3f];
[89] Fix | Delete
} while ($i < $count);
[90] Fix | Delete
[91] Fix | Delete
return $output;
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
function gensalt_private($input)
[95] Fix | Delete
{
[96] Fix | Delete
$output = '$P$';
[97] Fix | Delete
$output .= $this->itoa64[min($this->iteration_count_log2 +
[98] Fix | Delete
((PHP_VERSION >= '5') ? 5 : 3), 30)];
[99] Fix | Delete
$output .= $this->encode64($input, 6);
[100] Fix | Delete
[101] Fix | Delete
return $output;
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
function crypt_private($password, $setting)
[105] Fix | Delete
{
[106] Fix | Delete
$output = '*0';
[107] Fix | Delete
if (substr($setting, 0, 2) == $output)
[108] Fix | Delete
$output = '*1';
[109] Fix | Delete
[110] Fix | Delete
$id = substr($setting, 0, 3);
[111] Fix | Delete
# We use "$P$", phpBB3 uses "$H$" for the same thing
[112] Fix | Delete
if ($id != '$P$' && $id != '$H$')
[113] Fix | Delete
return $output;
[114] Fix | Delete
[115] Fix | Delete
$count_log2 = strpos($this->itoa64, $setting[3]);
[116] Fix | Delete
if ($count_log2 < 7 || $count_log2 > 30)
[117] Fix | Delete
return $output;
[118] Fix | Delete
[119] Fix | Delete
$count = 1 << $count_log2;
[120] Fix | Delete
[121] Fix | Delete
$salt = substr($setting, 4, 8);
[122] Fix | Delete
if (strlen($salt) != 8)
[123] Fix | Delete
return $output;
[124] Fix | Delete
[125] Fix | Delete
# We're kind of forced to use MD5 here since it's the only
[126] Fix | Delete
# cryptographic primitive available in all versions of PHP
[127] Fix | Delete
# currently in use. To implement our own low-level crypto
[128] Fix | Delete
# in PHP would result in much worse performance and
[129] Fix | Delete
# consequently in lower iteration counts and hashes that are
[130] Fix | Delete
# quicker to crack (by non-PHP code).
[131] Fix | Delete
if (PHP_VERSION >= '5') {
[132] Fix | Delete
$hash = md5($salt . $password, TRUE);
[133] Fix | Delete
do {
[134] Fix | Delete
$hash = md5($hash . $password, TRUE);
[135] Fix | Delete
} while (--$count);
[136] Fix | Delete
} else {
[137] Fix | Delete
$hash = pack('H*', md5($salt . $password));
[138] Fix | Delete
do {
[139] Fix | Delete
$hash = pack('H*', md5($hash . $password));
[140] Fix | Delete
} while (--$count);
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
$output = substr($setting, 0, 12);
[144] Fix | Delete
$output .= $this->encode64($hash, 16);
[145] Fix | Delete
[146] Fix | Delete
return $output;
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
function gensalt_extended($input)
[150] Fix | Delete
{
[151] Fix | Delete
$count_log2 = min($this->iteration_count_log2 + 8, 24);
[152] Fix | Delete
# This should be odd to not reveal weak DES keys, and the
[153] Fix | Delete
# maximum valid value is (2**24 - 1) which is odd anyway.
[154] Fix | Delete
$count = (1 << $count_log2) - 1;
[155] Fix | Delete
[156] Fix | Delete
$output = '_';
[157] Fix | Delete
$output .= $this->itoa64[$count & 0x3f];
[158] Fix | Delete
$output .= $this->itoa64[($count >> 6) & 0x3f];
[159] Fix | Delete
$output .= $this->itoa64[($count >> 12) & 0x3f];
[160] Fix | Delete
$output .= $this->itoa64[($count >> 18) & 0x3f];
[161] Fix | Delete
[162] Fix | Delete
$output .= $this->encode64($input, 3);
[163] Fix | Delete
[164] Fix | Delete
return $output;
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
function gensalt_blowfish($input)
[168] Fix | Delete
{
[169] Fix | Delete
# This one needs to use a different order of characters and a
[170] Fix | Delete
# different encoding scheme from the one in encode64() above.
[171] Fix | Delete
# We care because the last character in our encoded string will
[172] Fix | Delete
# only represent 2 bits. While two known implementations of
[173] Fix | Delete
# bcrypt will happily accept and correct a salt string which
[174] Fix | Delete
# has the 4 unused bits set to non-zero, we do not want to take
[175] Fix | Delete
# chances and we also do not want to waste an additional byte
[176] Fix | Delete
# of entropy.
[177] Fix | Delete
$itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
[178] Fix | Delete
[179] Fix | Delete
$output = '$2a$';
[180] Fix | Delete
$output .= chr(ord('0') + $this->iteration_count_log2 / 10);
[181] Fix | Delete
$output .= chr(ord('0') + $this->iteration_count_log2 % 10);
[182] Fix | Delete
$output .= '$';
[183] Fix | Delete
[184] Fix | Delete
$i = 0;
[185] Fix | Delete
do {
[186] Fix | Delete
$c1 = ord($input[$i++]);
[187] Fix | Delete
$output .= $itoa64[$c1 >> 2];
[188] Fix | Delete
$c1 = ($c1 & 0x03) << 4;
[189] Fix | Delete
if ($i >= 16) {
[190] Fix | Delete
$output .= $itoa64[$c1];
[191] Fix | Delete
break;
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
$c2 = ord($input[$i++]);
[195] Fix | Delete
$c1 |= $c2 >> 4;
[196] Fix | Delete
$output .= $itoa64[$c1];
[197] Fix | Delete
$c1 = ($c2 & 0x0f) << 2;
[198] Fix | Delete
[199] Fix | Delete
$c2 = ord($input[$i++]);
[200] Fix | Delete
$c1 |= $c2 >> 6;
[201] Fix | Delete
$output .= $itoa64[$c1];
[202] Fix | Delete
$output .= $itoa64[$c2 & 0x3f];
[203] Fix | Delete
} while (1);
[204] Fix | Delete
[205] Fix | Delete
return $output;
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
function HashPassword($password)
[209] Fix | Delete
{
[210] Fix | Delete
$random = '';
[211] Fix | Delete
[212] Fix | Delete
if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) {
[213] Fix | Delete
$random = $this->get_random_bytes(16);
[214] Fix | Delete
$hash =
[215] Fix | Delete
crypt($password, $this->gensalt_blowfish($random));
[216] Fix | Delete
if (strlen($hash) == 60)
[217] Fix | Delete
return $hash;
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) {
[221] Fix | Delete
if (strlen($random) < 3)
[222] Fix | Delete
$random = $this->get_random_bytes(3);
[223] Fix | Delete
$hash =
[224] Fix | Delete
crypt($password, $this->gensalt_extended($random));
[225] Fix | Delete
if (strlen($hash) == 20)
[226] Fix | Delete
return $hash;
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
if (strlen($random) < 6)
[230] Fix | Delete
$random = $this->get_random_bytes(6);
[231] Fix | Delete
$hash =
[232] Fix | Delete
$this->crypt_private($password,
[233] Fix | Delete
$this->gensalt_private($random));
[234] Fix | Delete
if (strlen($hash) == 34)
[235] Fix | Delete
return $hash;
[236] Fix | Delete
[237] Fix | Delete
# Returning '*' on error is safe here, but would _not_ be safe
[238] Fix | Delete
# in a crypt(3)-like function used _both_ for generating new
[239] Fix | Delete
# hashes and for validating passwords against existing hashes.
[240] Fix | Delete
return '*';
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
function CheckPassword($password, $stored_hash)
[244] Fix | Delete
{
[245] Fix | Delete
$hash = $this->crypt_private($password, $stored_hash);
[246] Fix | Delete
if ($hash[0] == '*')
[247] Fix | Delete
$hash = crypt($password, $stored_hash);
[248] Fix | Delete
[249] Fix | Delete
return $hash == $stored_hash;
[250] Fix | Delete
}
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
?>
[254] Fix | Delete
[255] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function