wp/wp-includes/class-phpass.php
author ymh <ymh.work@gmail.com>
Fri, 05 Sep 2025 18:40:08 +0200
changeset 21 48c4eec2b7e6
parent 18 be944660c56a
child 22 8c2e4d02f4ef
permissions -rw-r--r--
Add CLAUDE.md documentation and sync WordPress core files - Add comprehensive CLAUDE.md documentation file with project architecture, development setup, database operations, WordPress CLI usage, file sync procedures, and Mercurial commands - Update WordPress core files from wordpress/ to wp/ directory - Sync latest WordPress admin interface, includes, and core functionality - Update plugins: portfolio plugin with latest BWS framework and fancybox integration - Maintain custom configuration and theme files 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Portable PHP password hashing framework.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 * @package phpass
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     5
 * @since 2.5.0
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
     6
 * @version 0.5 / WordPress
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     7
 * @link https://www.openwall.com/phpass/
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
#
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    11
# Portable PHP password hashing framework.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    12
#
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    13
# Version 0.5 / WordPress.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    14
#
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
# Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
# the public domain.  Revised in subsequent years, still public domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
#
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
# There's absolutely no warranty.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
#
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    20
# The homepage URL for this framework is:
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    21
#
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    22
#	http://www.openwall.com/phpass/
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    23
#
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
# Please be sure to update the Version line if you edit this file in any way.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
# It is suggested that you leave the main version number intact, but indicate
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
# your project name (after the slash) and add your own revision information.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
#
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
# Please do not change the "private" password hashing method implemented in
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
# here, thereby making your hashes incompatible.  However, if you must, please
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
# change the hash type identifier (the "$P$") to something different.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
#
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
# Obviously, since this code is in the public domain, the above are not
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
# requirements (there can be none), but merely suggestions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
#
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
 * Portable PHP password hashing framework.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
 * @package phpass
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    40
 * @version 0.5 / WordPress
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    41
 * @link https://www.openwall.com/phpass/
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    42
 * @since 2.5.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
class PasswordHash {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	var $itoa64;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
	var $iteration_count_log2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	var $portable_hashes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
	var $random_state;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    50
	function __construct($iteration_count_log2, $portable_hashes)
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
	{
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
		$this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
		if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
			$iteration_count_log2 = 8;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
		$this->iteration_count_log2 = $iteration_count_log2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
		$this->portable_hashes = $portable_hashes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    60
		$this->random_state = microtime();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    61
		if (function_exists('getmypid'))
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    62
			$this->random_state .= getmypid();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    65
	function PasswordHash($iteration_count_log2, $portable_hashes)
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    66
	{
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    67
		self::__construct($iteration_count_log2, $portable_hashes);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    68
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    69
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
	function get_random_bytes($count)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	{
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
		$output = '';
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    73
		if (@is_readable('/dev/urandom') &&
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
		    ($fh = @fopen('/dev/urandom', 'rb'))) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
			$output = fread($fh, $count);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
			fclose($fh);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
		if (strlen($output) < $count) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
			$output = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
			for ($i = 0; $i < $count; $i += 16) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
				$this->random_state =
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
				    md5(microtime() . $this->random_state);
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    84
				$output .= md5($this->random_state, TRUE);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
			$output = substr($output, 0, $count);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
		return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	function encode64($input, $count)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
	{
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		$output = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
		$i = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
		do {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
			$value = ord($input[$i++]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
			$output .= $this->itoa64[$value & 0x3f];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
			if ($i < $count)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
				$value |= ord($input[$i]) << 8;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
			$output .= $this->itoa64[($value >> 6) & 0x3f];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
			if ($i++ >= $count)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
			if ($i < $count)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
				$value |= ord($input[$i]) << 16;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
			$output .= $this->itoa64[($value >> 12) & 0x3f];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
			if ($i++ >= $count)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
			$output .= $this->itoa64[($value >> 18) & 0x3f];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
		} while ($i < $count);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
		return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
	function gensalt_private($input)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
	{
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
		$output = '$P$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
		$output .= $this->itoa64[min($this->iteration_count_log2 +
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
			((PHP_VERSION >= '5') ? 5 : 3), 30)];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
		$output .= $this->encode64($input, 6);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
		return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
	function crypt_private($password, $setting)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	{
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
		$output = '*0';
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   128
		if (substr($setting, 0, 2) === $output)
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
			$output = '*1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
		$id = substr($setting, 0, 3);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
		# We use "$P$", phpBB3 uses "$H$" for the same thing
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   133
		if ($id !== '$P$' && $id !== '$H$')
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
			return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
		$count_log2 = strpos($this->itoa64, $setting[3]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
		if ($count_log2 < 7 || $count_log2 > 30)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
			return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
		$count = 1 << $count_log2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
		$salt = substr($setting, 4, 8);
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   143
		if (strlen($salt) !== 8)
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
			return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   146
		# We were kind of forced to use MD5 here since it's the only
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   147
		# cryptographic primitive that was available in all versions
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   148
		# of PHP in use.  To implement our own low-level crypto in PHP
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   149
		# would have resulted in much worse performance and
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
		# consequently in lower iteration counts and hashes that are
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
		# quicker to crack (by non-PHP code).
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   152
		$hash = md5($salt . $password, TRUE);
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   153
		do {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   154
			$hash = md5($hash . $password, TRUE);
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   155
		} while (--$count);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
		$output = substr($setting, 0, 12);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
		$output .= $this->encode64($hash, 16);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
		return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
	function gensalt_blowfish($input)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
	{
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
		# This one needs to use a different order of characters and a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
		# different encoding scheme from the one in encode64() above.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
		# We care because the last character in our encoded string will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
		# only represent 2 bits.  While two known implementations of
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
		# bcrypt will happily accept and correct a salt string which
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
		# has the 4 unused bits set to non-zero, we do not want to take
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
		# chances and we also do not want to waste an additional byte
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
		# of entropy.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
		$itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
		$output = '$2a$';
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   176
		$output .= chr((int)(ord('0') + $this->iteration_count_log2 / 10));
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   177
		$output .= chr((ord('0') + $this->iteration_count_log2 % 10));
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
		$output .= '$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
		$i = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
		do {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
			$c1 = ord($input[$i++]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
			$output .= $itoa64[$c1 >> 2];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
			$c1 = ($c1 & 0x03) << 4;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
			if ($i >= 16) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
				$output .= $itoa64[$c1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
			$c2 = ord($input[$i++]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
			$c1 |= $c2 >> 4;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
			$output .= $itoa64[$c1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
			$c1 = ($c2 & 0x0f) << 2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
			$c2 = ord($input[$i++]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
			$c1 |= $c2 >> 6;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
			$output .= $itoa64[$c1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
			$output .= $itoa64[$c2 & 0x3f];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
		} while (1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
		return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
	function HashPassword($password)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
	{
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   206
		if ( strlen( $password ) > 4096 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
			return '*';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   209
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
		$random = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   212
		if (CRYPT_BLOWFISH === 1 && !$this->portable_hashes) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
			$random = $this->get_random_bytes(16);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
			$hash =
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
			    crypt($password, $this->gensalt_blowfish($random));
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   216
			if (strlen($hash) === 60)
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
				return $hash;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
		if (strlen($random) < 6)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
			$random = $this->get_random_bytes(6);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
		$hash =
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
		    $this->crypt_private($password,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
		    $this->gensalt_private($random));
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   225
		if (strlen($hash) === 34)
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
			return $hash;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
		# Returning '*' on error is safe here, but would _not_ be safe
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
		# in a crypt(3)-like function used _both_ for generating new
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
		# hashes and for validating passwords against existing hashes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
		return '*';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
	function CheckPassword($password, $stored_hash)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
	{
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   236
		if ( strlen( $password ) > 4096 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   237
			return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   239
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
		$hash = $this->crypt_private($password, $stored_hash);
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   241
		if ($hash[0] === '*')
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
			$hash = crypt($password, $stored_hash);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   244
		# This is not constant-time.  In order to keep the code simple,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   245
		# for timing safety we currently rely on the salts being
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   246
		# unpredictable, which they are at least in the non-fallback
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   247
		# cases (that is, when we use /dev/urandom and bcrypt).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
		return $hash === $stored_hash;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
	}
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   250
}