Make WordPress Core

Changeset 59030


Ignore:
Timestamp:
09/17/2024 09:06:30 PM (2 years ago)
Author:
desrosj
Message:

External Libraries: Update PHPass library.

This updates the PHPass library to version 0.5.4 while maintaining the adjustments introduced in [30466].

Props jrf.
Fixes #62058.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-phpass.php

    r55310 r59030  
    1111# Portable PHP password hashing framework.
    1212#
    13 # Version 0.5 / WordPress.
     13# Version 0.5.4 / WordPress.
    1414#
    1515# Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in
    … …  
    5252                $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    5353
    54                 if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31)
     54                if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) {
    5555                        $iteration_count_log2 = 8;
     56                }
    5657                $this->iteration_count_log2 = $iteration_count_log2;
    5758
    … …  
    5960
    6061                $this->random_state = microtime();
    61                 if (function_exists('getmypid'))
     62                if (function_exists('getmypid')) {
    6263                        $this->random_state .= getmypid();
     64                }
    6365        }
    6466
    … …  
    9799                        $value = ord($input[$i++]);
    98100                        $output .= $this->itoa64[$value & 0x3f];
    99                         if ($i < $count)
     101                        if ($i < $count) {
    100102                                $value |= ord($input[$i]) << 8;
     103                        }
    101104                        $output .= $this->itoa64[($value >> 6) & 0x3f];
    102                         if ($i++ >= $count)
     105                        if ($i++ >= $count) {
    103106                                break;
    104                         if ($i < $count)
     107                        }
     108                        if ($i < $count) {
    105109                                $value |= ord($input[$i]) << 16;
     110                        }
    106111                        $output .= $this->itoa64[($value >> 12) & 0x3f];
    107                         if ($i++ >= $count)
     112                        if ($i++ >= $count) {
    108113                                break;
     114                        }
    109115                        $output .= $this->itoa64[($value >> 18) & 0x3f];
    110116                } while ($i < $count);
    … …  
    116122        {
    117123                $output = '$P$';
    118                 $output .= $this->itoa64[min($this->iteration_count_log2 +
    119                         ((PHP_VERSION >= '5') ? 5 : 3), 30)];
     124                $output .= $this->itoa64[min($this->iteration_count_log2 + 5,
     125                    30)];
    120126                $output .= $this->encode64($input, 6);
    121127
    … …  
    126132        {
    127133                $output = '*0';
    128                 if (substr($setting, 0, 2) === $output)
     134                if (substr($setting, 0, 2) === $output) {
    129135                        $output = '*1';
     136                }
    130137
    131138                $id = substr($setting, 0, 3);
    132139                # We use "$P$", phpBB3 uses "$H$" for the same thing
    133                 if ($id !== '$P$' && $id !== '$H$')
     140                if ($id !== '$P$' && $id !== '$H$') {
    134141                        return $output;
     142                }
    135143
    136144                $count_log2 = strpos($this->itoa64, $setting[3]);
    137                 if ($count_log2 < 7 || $count_log2 > 30)
     145                if ($count_log2 < 7 || $count_log2 > 30) {
    138146                        return $output;
     147                }
    139148
    140149                $count = 1 << $count_log2;
    141150
    142151                $salt = substr($setting, 4, 8);
    143                 if (strlen($salt) !== 8)
     152                if (strlen($salt) !== 8) {
    144153                        return $output;
     154                }
    145155
    146156                # We were kind of forced to use MD5 here since it's the only
    … …  
    175185                $output = '$2a$';
    176186                $output .= chr((int)(ord('0') + $this->iteration_count_log2 / 10));
    177                 $output .= chr((ord('0') + $this->iteration_count_log2 % 10));
     187                $output .= chr(ord('0') + $this->iteration_count_log2 % 10);
    178188                $output .= '$';
    179189
    … …  
    214224                        $hash =
    215225                            crypt($password, $this->gensalt_blowfish($random));
    216                         if (strlen($hash) === 60)
     226                        if (strlen($hash) === 60) {
    217227                                return $hash;
    218                 }
    219 
    220                 if (strlen($random) < 6)
     228                        }
     229                }
     230
     231                if (strlen($random) < 6) {
    221232                        $random = $this->get_random_bytes(6);
     233                }
    222234                $hash =
    223235                    $this->crypt_private($password,
    224236                    $this->gensalt_private($random));
    225                 if (strlen($hash) === 34)
     237                if (strlen($hash) === 34) {
    226238                        return $hash;
     239                }
    227240
    228241                # Returning '*' on error is safe here, but would _not_ be safe
    … …  
    239252
    240253                $hash = $this->crypt_private($password, $stored_hash);
    241                 if ($hash[0] === '*')
     254                if ($hash[0] === '*') {
    242255                        $hash = crypt($password, $stored_hash);
     256                }
    243257
    244258                # This is not constant-time.  In order to keep the code simple,
Note: See TracChangeset for help on using the changeset viewer.