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