Make WordPress Core


Ignore:
Timestamp:
02/17/2025 11:22:33 AM (3 months ago)
Author:
johnbillion
Message:

Security: Switch to using bcrypt for hashing user passwords and BLAKE2b for hashing application passwords and security keys.

Passwords and security keys that were saved in prior versions of WordPress will continue to work. Each user's password will be opportunistically rehashed and resaved when they next subsequently log in using a valid password.

The following new functions have been introduced:

  • wp_password_needs_rehash()
  • wp_fast_hash()
  • wp_verify_fast_hash()

The following new filters have been introduced:

  • password_needs_rehash
  • wp_hash_password_algorithm
  • wp_hash_password_options

Props ayeshrajans, bgermann, dd32, deadduck169, desrosj, haozi, harrym, iandunn, jammycakes, joehoyle, johnbillion, mbijon, mojorob, mslavco, my1xt, nacin, otto42, paragoninitiativeenterprises, paulkevan, rmccue, ryanhellyer, scribu, swalkinshaw, synchro, th23, timothyblynjacobs, tomdxw, westi, xknown.

Additional thanks go to the Roots team, Soatok, Calvin Alkan, and Raphael Ahrens.

Fixes #21022, #44628

File:
1 edited

Legend:

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

    r59754 r59828  
    6161     * @since 5.6.0
    6262     * @since 5.7.0 Returns WP_Error if application name already exists.
     63     * @since 6.8.0 The hashed password value now uses wp_fast_hash() instead of phpass.
    6364     *
    6465     * @param int   $user_id  User ID.
     
    9697
    9798        $new_password    = wp_generate_password( static::PW_LENGTH, false );
    98         $hashed_password = wp_hash_password( $new_password );
     99        $hashed_password = self::hash_password( $new_password );
    99100
    100101        $new_item = array(
     
    125126         *
    126127         * @since 5.6.0
     128         * @since 6.8.0 The hashed password value now uses wp_fast_hash() instead of phpass.
    127129         *
    128130         * @param int    $user_id      The user ID.
     
    250252     *
    251253     * @since 5.6.0
     254     * @since 6.8.0 The actual password should now be hashed using wp_fast_hash().
    252255     *
    253256     * @param int    $user_id User ID.
     
    297300             *
    298301             * @since 5.6.0
     302             * @since 6.8.0 The password is now hashed using wp_fast_hash() instead of phpass.
     303             *              Existing passwords may still be hashed using phpass.
    299304             *
    300305             * @param int   $user_id The user ID.
     
    468473        return trim( chunk_split( $raw_password, 4, ' ' ) );
    469474    }
     475
     476    /**
     477     * Hashes a plaintext application password.
     478     *
     479     * @since 6.8.0
     480     *
     481     * @param string $password Plaintext password.
     482     * @return string Hashed password.
     483     */
     484    public static function hash_password(
     485        #[\SensitiveParameter]
     486        string $password
     487    ): string {
     488        return wp_fast_hash( $password );
     489    }
     490
     491    /**
     492     * Checks a plaintext application password against a hashed password.
     493     *
     494     * @since 6.8.0
     495     *
     496     * @param string $password Plaintext password.
     497     * @param string $hash     Hash of the password to check against.
     498     * @return bool Whether the password matches the hashed password.
     499     */
     500    public static function check_password(
     501        #[\SensitiveParameter]
     502        string $password,
     503        string $hash
     504    ): bool {
     505        return wp_verify_fast_hash( $password, $hash );
     506    }
    470507}
Note: See TracChangeset for help on using the changeset viewer.