Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../var/softacul.../elkarte
File: update_pass.php
<?php
[0] Fix | Delete
#
[1] Fix | Delete
# Portable PHP password hashing framework.
[2] Fix | Delete
#
[3] Fix | Delete
# Version 0.3 / elkarte.
[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
[26] Fix | Delete
[27] Fix | Delete
$resp = __validateLoginPassword('[[admin_pass]]', '', '[[admin_username]]', true);
[28] Fix | Delete
echo '<update_pass>'.$resp.'</update_pass>';
[29] Fix | Delete
[30] Fix | Delete
function __validateLoginPassword($password, $hash, $user = '', $returnhash = false)
[31] Fix | Delete
{
[32] Fix | Delete
global $error;
[33] Fix | Delete
[34] Fix | Delete
// Base-2 logarithm of the iteration count used for password stretching, the
[35] Fix | Delete
// higher the number the more secure and CPU time consuming
[36] Fix | Delete
$hash_cost_log2 = 10;
[37] Fix | Delete
[38] Fix | Delete
// Do we require the hashes to be portable to older systems (less secure)?
[39] Fix | Delete
$hash_portable = false;
[40] Fix | Delete
[41] Fix | Delete
// Get an instance of the hasher
[42] Fix | Delete
$hasher = new PasswordHash($hash_cost_log2, $hash_portable);
[43] Fix | Delete
[44] Fix | Delete
// If the password is not 64 characters, lets make it a (SHA-256)
[45] Fix | Delete
if (strlen($password) !== 64){
[46] Fix | Delete
$password = hash('sha256', strtolower($user) . __un_htmlspecialchars($password));
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
// They need a password hash, something to save in the db?
[50] Fix | Delete
if ($returnhash)
[51] Fix | Delete
{
[52] Fix | Delete
$passhash = $hasher->HashPassword($password);
[53] Fix | Delete
[54] Fix | Delete
// Something is not right, we can not generate a valid hash that's <20 characters
[55] Fix | Delete
if (strlen($passhash) < 20){
[56] Fix | Delete
$error[] = 'The hashed password is less than 20 characters';
[57] Fix | Delete
return false;
[58] Fix | Delete
}
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
unset($hasher);
[62] Fix | Delete
[63] Fix | Delete
return $passhash;
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
[67] Fix | Delete
[68] Fix | Delete
class PasswordHash {
[69] Fix | Delete
var $itoa64;
[70] Fix | Delete
var $iteration_count_log2;
[71] Fix | Delete
var $portable_hashes;
[72] Fix | Delete
var $random_state;
[73] Fix | Delete
[74] Fix | Delete
public function __construct( $iteration_count_log2, $portable_hashes )
[75] Fix | Delete
{
[76] Fix | Delete
$this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
[77] Fix | Delete
[78] Fix | Delete
if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31)
[79] Fix | Delete
$iteration_count_log2 = 8;
[80] Fix | Delete
$this->iteration_count_log2 = $iteration_count_log2;
[81] Fix | Delete
[82] Fix | Delete
$this->portable_hashes = $portable_hashes;
[83] Fix | Delete
[84] Fix | Delete
$this->random_state = microtime() . uniqid(rand(), TRUE);
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
private function get_random_bytes($count)
[88] Fix | Delete
{
[89] Fix | Delete
$output = '';
[90] Fix | Delete
[91] Fix | Delete
// PHP >= 7
[92] Fix | Delete
if (is_callable('random_bytes')) {
[93] Fix | Delete
$output = random_bytes($count);
[94] Fix | Delete
}
[95] Fix | Delete
// *nix
[96] Fix | Delete
elseif (@is_readable('/dev/urandom') &&
[97] Fix | Delete
($fh = @fopen('/dev/urandom', 'rb'))) {
[98] Fix | Delete
$output = fread($fh, $count);
[99] Fix | Delete
fclose($fh);
[100] Fix | Delete
}
[101] Fix | Delete
// This is much to slow on windows php < 5.3.4
[102] Fix | Delete
elseif (function_exists('openssl_random_pseudo_bytes') &&
[103] Fix | Delete
(substr(PHP_OS, 0, 3) !== 'WIN' || version_compare(PHP_VERSION, '5.3.4', '>='))) {
[104] Fix | Delete
$output = openssl_random_pseudo_bytes($count);
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
// Do it ourselves then
[108] Fix | Delete
if (strlen($output) < $count) {
[109] Fix | Delete
$output = '';
[110] Fix | Delete
for ($i = 0; $i < $count; $i += 16) {
[111] Fix | Delete
$this->random_state =
[112] Fix | Delete
md5(microtime() . $this->random_state);
[113] Fix | Delete
$output .=
[114] Fix | Delete
pack('H*', md5($this->random_state));
[115] Fix | Delete
}
[116] Fix | Delete
$output = substr($output, 0, $count);
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
return $output;
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
private function encode64($input, $count)
[123] Fix | Delete
{
[124] Fix | Delete
$output = '';
[125] Fix | Delete
$i = 0;
[126] Fix | Delete
do {
[127] Fix | Delete
$value = ord($input[$i++]);
[128] Fix | Delete
$output .= $this->itoa64[$value & 0x3f];
[129] Fix | Delete
if ($i < $count)
[130] Fix | Delete
$value |= ord($input[$i]) << 8;
[131] Fix | Delete
$output .= $this->itoa64[($value >> 6) & 0x3f];
[132] Fix | Delete
if ($i++ >= $count)
[133] Fix | Delete
break;
[134] Fix | Delete
if ($i < $count)
[135] Fix | Delete
$value |= ord($input[$i]) << 16;
[136] Fix | Delete
$output .= $this->itoa64[($value >> 12) & 0x3f];
[137] Fix | Delete
if ($i++ >= $count)
[138] Fix | Delete
break;
[139] Fix | Delete
$output .= $this->itoa64[($value >> 18) & 0x3f];
[140] Fix | Delete
} while ($i < $count);
[141] Fix | Delete
[142] Fix | Delete
return $output;
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
private function gensalt_private($input)
[146] Fix | Delete
{
[147] Fix | Delete
$output = '$P$';
[148] Fix | Delete
$output .= $this->itoa64[min($this->iteration_count_log2 +
[149] Fix | Delete
((PHP_VERSION >= '5') ? 5 : 3), 30)];
[150] Fix | Delete
$output .= $this->encode64($input, 6);
[151] Fix | Delete
[152] Fix | Delete
return $output;
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
private function crypt_private($password, $setting)
[156] Fix | Delete
{
[157] Fix | Delete
$output = '*0';
[158] Fix | Delete
if (substr($setting, 0, 2) == $output)
[159] Fix | Delete
$output = '*1';
[160] Fix | Delete
[161] Fix | Delete
$id = substr($setting, 0, 3);
[162] Fix | Delete
# We use "$P$", phpBB3 uses "$H$" for the same thing
[163] Fix | Delete
if ($id != '$P$' && $id != '$H$')
[164] Fix | Delete
return $output;
[165] Fix | Delete
[166] Fix | Delete
$count_log2 = strpos($this->itoa64, $setting[3]);
[167] Fix | Delete
if ($count_log2 < 7 || $count_log2 > 30)
[168] Fix | Delete
return $output;
[169] Fix | Delete
[170] Fix | Delete
$count = 1 << $count_log2;
[171] Fix | Delete
[172] Fix | Delete
$salt = substr($setting, 4, 8);
[173] Fix | Delete
if (strlen($salt) != 8)
[174] Fix | Delete
return $output;
[175] Fix | Delete
[176] Fix | Delete
# We're kind of forced to use MD5 here since it's the only
[177] Fix | Delete
# cryptographic primitive available in all versions of PHP
[178] Fix | Delete
# currently in use. To implement our own low-level crypto
[179] Fix | Delete
# in PHP would result in much worse performance and
[180] Fix | Delete
# consequently in lower iteration counts and hashes that are
[181] Fix | Delete
# quicker to crack (by non-PHP code).
[182] Fix | Delete
if (PHP_VERSION >= '5') {
[183] Fix | Delete
$hash = md5($salt . $password, TRUE);
[184] Fix | Delete
do {
[185] Fix | Delete
$hash = md5($hash . $password, TRUE);
[186] Fix | Delete
} while (--$count);
[187] Fix | Delete
} else {
[188] Fix | Delete
$hash = pack('H*', md5($salt . $password));
[189] Fix | Delete
do {
[190] Fix | Delete
$hash = pack('H*', md5($hash . $password));
[191] Fix | Delete
} while (--$count);
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
$output = substr($setting, 0, 12);
[195] Fix | Delete
$output .= $this->encode64($hash, 16);
[196] Fix | Delete
[197] Fix | Delete
return $output;
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
private function gensalt_extended($input)
[201] Fix | Delete
{
[202] Fix | Delete
$count_log2 = min($this->iteration_count_log2 + 8, 24);
[203] Fix | Delete
# This should be odd to not reveal weak DES keys, and the
[204] Fix | Delete
# maximum valid value is (2**24 - 1) which is odd anyway.
[205] Fix | Delete
$count = (1 << $count_log2) - 1;
[206] Fix | Delete
[207] Fix | Delete
$output = '_';
[208] Fix | Delete
$output .= $this->itoa64[$count & 0x3f];
[209] Fix | Delete
$output .= $this->itoa64[($count >> 6) & 0x3f];
[210] Fix | Delete
$output .= $this->itoa64[($count >> 12) & 0x3f];
[211] Fix | Delete
$output .= $this->itoa64[($count >> 18) & 0x3f];
[212] Fix | Delete
[213] Fix | Delete
$output .= $this->encode64($input, 3);
[214] Fix | Delete
[215] Fix | Delete
return $output;
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
private function gensalt_blowfish($input)
[219] Fix | Delete
{
[220] Fix | Delete
# This one needs to use a different order of characters and a
[221] Fix | Delete
# different encoding scheme from the one in encode64() above.
[222] Fix | Delete
# We care because the last character in our encoded string will
[223] Fix | Delete
# only represent 2 bits. While two known implementations of
[224] Fix | Delete
# bcrypt will happily accept and correct a salt string which
[225] Fix | Delete
# has the 4 unused bits set to non-zero, we do not want to take
[226] Fix | Delete
# chances and we also do not want to waste an additional byte
[227] Fix | Delete
# of entropy.
[228] Fix | Delete
$itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
[229] Fix | Delete
[230] Fix | Delete
$output = '$2a$';
[231] Fix | Delete
$output .= chr(ord('0') + $this->iteration_count_log2 / 10);
[232] Fix | Delete
$output .= chr(ord('0') + $this->iteration_count_log2 % 10);
[233] Fix | Delete
$output .= '$';
[234] Fix | Delete
[235] Fix | Delete
$i = 0;
[236] Fix | Delete
do {
[237] Fix | Delete
$c1 = ord($input[$i++]);
[238] Fix | Delete
$output .= $itoa64[$c1 >> 2];
[239] Fix | Delete
$c1 = ($c1 & 0x03) << 4;
[240] Fix | Delete
if ($i >= 16) {
[241] Fix | Delete
$output .= $itoa64[$c1];
[242] Fix | Delete
break;
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
$c2 = ord($input[$i++]);
[246] Fix | Delete
$c1 |= $c2 >> 4;
[247] Fix | Delete
$output .= $itoa64[$c1];
[248] Fix | Delete
$c1 = ($c2 & 0x0f) << 2;
[249] Fix | Delete
[250] Fix | Delete
$c2 = ord($input[$i++]);
[251] Fix | Delete
$c1 |= $c2 >> 6;
[252] Fix | Delete
$output .= $itoa64[$c1];
[253] Fix | Delete
$output .= $itoa64[$c2 & 0x3f];
[254] Fix | Delete
} while (1);
[255] Fix | Delete
[256] Fix | Delete
return $output;
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
public function HashPassword($password)
[260] Fix | Delete
{
[261] Fix | Delete
if ( strlen( $password ) > 4096 )
[262] Fix | Delete
return '*';
[263] Fix | Delete
[264] Fix | Delete
$random = '';
[265] Fix | Delete
[266] Fix | Delete
if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) {
[267] Fix | Delete
$random = $this->get_random_bytes(16);
[268] Fix | Delete
$hash =
[269] Fix | Delete
crypt($password, $this->gensalt_blowfish($random));
[270] Fix | Delete
if (strlen($hash) == 60)
[271] Fix | Delete
return $hash;
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) {
[275] Fix | Delete
if (strlen($random) < 3)
[276] Fix | Delete
$random = $this->get_random_bytes(3);
[277] Fix | Delete
$hash =
[278] Fix | Delete
crypt($password, $this->gensalt_extended($random));
[279] Fix | Delete
if (strlen($hash) == 20)
[280] Fix | Delete
return $hash;
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
if (strlen($random) < 6)
[284] Fix | Delete
$random = $this->get_random_bytes(6);
[285] Fix | Delete
$hash =
[286] Fix | Delete
$this->crypt_private($password,
[287] Fix | Delete
$this->gensalt_private($random));
[288] Fix | Delete
if (strlen($hash) == 34)
[289] Fix | Delete
return $hash;
[290] Fix | Delete
[291] Fix | Delete
# Returning '*' on error is safe here, but would _not_ be safe
[292] Fix | Delete
# in a crypt(3)-like function used _both_ for generating new
[293] Fix | Delete
# hashes and for validating passwords against existing hashes.
[294] Fix | Delete
return '*';
[295] Fix | Delete
}
[296] Fix | Delete
}
[297] Fix | Delete
[298] Fix | Delete
[299] Fix | Delete
function __un_htmlspecialchars($string)
[300] Fix | Delete
{
[301] Fix | Delete
$string = htmlspecialchars_decode($string, ENT_QUOTES);
[302] Fix | Delete
$string = str_replace('&nbsp;', ' ', $string);
[303] Fix | Delete
[304] Fix | Delete
return $string;
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
@unlink('update_pass.php');
[308] Fix | Delete
?>
[309] Fix | Delete
[310] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function