Make WordPress Core


Ignore:
Timestamp:
02/28/2025 06:51:44 PM (8 months ago)
Author:
johnbillion
Message:

Security: Reintroduce support for passwords hashed with MD5.

This reinstates the ability for a user to log in to an account where the password is hashed using MD5. This means that the ability to reset a password directly in the database using an SQL query or a database administration tool will be retained without the need to implement or integrate with bcrypt or phpass.

A password hashed with MD5 will get upgraded to bcrypt at the point where a user successfully logs in, just as is the case with a phpass hash.

Props audrasjb, aaronjorbin, johnbillion, david-innes, benniledl.

See #21022.

File:
1 edited

Legend:

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

    r59858 r59893  
    27252725     * @since 6.8.0 Passwords in WordPress are now hashed with bcrypt by default. A
    27262726     *              password that wasn't hashed with bcrypt will be checked with phpass.
    2727      *              Passwords hashed with md5 are no longer supported.
    27282727     *
    27292728     * @global PasswordHash $wp_hasher phpass object. Used as a fallback for verifying
     
    27432742        global $wp_hasher;
    27442743
    2745         $check = false;
    2746 
    2747         // If the hash is still md5 or otherwise truncated then invalidate it.
    27482744        if ( strlen( $hash ) <= 32 ) {
    2749             /**
    2750              * Filters whether the plaintext password matches the hashed password.
    2751              *
    2752              * @since 2.5.0
    2753              * @since 6.8.0 Passwords are now hashed with bcrypt by default.
    2754              *              Old passwords may still be hashed with phpass.
    2755              *
    2756              * @param bool       $check    Whether the passwords match.
    2757              * @param string     $password The plaintext password.
    2758              * @param string     $hash     The hashed password.
    2759              * @param string|int $user_id  Optional ID of a user associated with the password.
    2760              *                             Can be empty.
    2761              */
    2762             return apply_filters( 'check_password', $check, $password, $hash, $user_id );
    2763         }
    2764 
    2765         if ( ! empty( $wp_hasher ) ) {
     2745            // Check the hash using md5 regardless of the current hashing mechanism.
     2746            $check = hash_equals( $hash, md5( $password ) );
     2747        } elseif ( ! empty( $wp_hasher ) ) {
    27662748            // Check the password using the overridden hasher.
    27672749            $check = $wp_hasher->CheckPassword( $password, $hash );
    27682750        } elseif ( strlen( $password ) > 4096 ) {
     2751            // Passwords longer than 4096 characters are not supported.
    27692752            $check = false;
    27702753        } elseif ( str_starts_with( $hash, '$wp' ) ) {
     
    27812764        }
    27822765
    2783         /** This filter is documented in wp-includes/pluggable.php */
     2766        /**
     2767         * Filters whether the plaintext password matches the hashed password.
     2768         *
     2769         * @since 2.5.0
     2770         * @since 6.8.0 Passwords are now hashed with bcrypt by default.
     2771         *              Old passwords may still be hashed with phpass or md5.
     2772         *
     2773         * @param bool       $check    Whether the passwords match.
     2774         * @param string     $password The plaintext password.
     2775         * @param string     $hash     The hashed password.
     2776         * @param string|int $user_id  Optional ID of a user associated with the password.
     2777         *                             Can be empty.
     2778         */
    27842779        return apply_filters( 'check_password', $check, $password, $hash, $user_id );
    27852780    }
Note: See TracChangeset for help on using the changeset viewer.