Edit File by line
/home/zeestwma/ajeebong.../wp-inclu...
File: class-wp-application-passwords.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WP_Application_Passwords class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @since 5.6.0
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Class for displaying, modifying, and sanitizing application passwords.
[9] Fix | Delete
*
[10] Fix | Delete
* @package WordPress
[11] Fix | Delete
*/
[12] Fix | Delete
#[AllowDynamicProperties]
[13] Fix | Delete
class WP_Application_Passwords {
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* The application passwords user meta key.
[17] Fix | Delete
*
[18] Fix | Delete
* @since 5.6.0
[19] Fix | Delete
*
[20] Fix | Delete
* @var string
[21] Fix | Delete
*/
[22] Fix | Delete
const USERMETA_KEY_APPLICATION_PASSWORDS = '_application_passwords';
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* The option name used to store whether application passwords are in use.
[26] Fix | Delete
*
[27] Fix | Delete
* @since 5.6.0
[28] Fix | Delete
*
[29] Fix | Delete
* @var string
[30] Fix | Delete
*/
[31] Fix | Delete
const OPTION_KEY_IN_USE = 'using_application_passwords';
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* The generated application password length.
[35] Fix | Delete
*
[36] Fix | Delete
* @since 5.6.0
[37] Fix | Delete
*
[38] Fix | Delete
* @var int
[39] Fix | Delete
*/
[40] Fix | Delete
const PW_LENGTH = 24;
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Checks if application passwords are being used by the site.
[44] Fix | Delete
*
[45] Fix | Delete
* This returns true if at least one application password has ever been created.
[46] Fix | Delete
*
[47] Fix | Delete
* @since 5.6.0
[48] Fix | Delete
*
[49] Fix | Delete
* @return bool
[50] Fix | Delete
*/
[51] Fix | Delete
public static function is_in_use() {
[52] Fix | Delete
$network_id = get_main_network_id();
[53] Fix | Delete
return (bool) get_network_option( $network_id, self::OPTION_KEY_IN_USE );
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Creates a new application password.
[58] Fix | Delete
*
[59] Fix | Delete
* @since 5.6.0
[60] Fix | Delete
* @since 5.7.0 Returns WP_Error if application name already exists.
[61] Fix | Delete
* @since 6.8.0 The hashed password value now uses wp_fast_hash() instead of phpass.
[62] Fix | Delete
*
[63] Fix | Delete
* @param int $user_id User ID.
[64] Fix | Delete
* @param array $args {
[65] Fix | Delete
* Arguments used to create the application password.
[66] Fix | Delete
*
[67] Fix | Delete
* @type string $name The name of the application password.
[68] Fix | Delete
* @type string $app_id A UUID provided by the application to uniquely identify it.
[69] Fix | Delete
* }
[70] Fix | Delete
* @return array|WP_Error {
[71] Fix | Delete
* Application password details, or a WP_Error instance if an error occurs.
[72] Fix | Delete
*
[73] Fix | Delete
* @type string $0 The generated application password in plain text.
[74] Fix | Delete
* @type array $1 {
[75] Fix | Delete
* The details about the created password.
[76] Fix | Delete
*
[77] Fix | Delete
* @type string $uuid The unique identifier for the application password.
[78] Fix | Delete
* @type string $app_id A UUID provided by the application to uniquely identify it.
[79] Fix | Delete
* @type string $name The name of the application password.
[80] Fix | Delete
* @type string $password A one-way hash of the password.
[81] Fix | Delete
* @type int $created Unix timestamp of when the password was created.
[82] Fix | Delete
* @type null $last_used Null.
[83] Fix | Delete
* @type null $last_ip Null.
[84] Fix | Delete
* }
[85] Fix | Delete
* }
[86] Fix | Delete
*/
[87] Fix | Delete
public static function create_new_application_password( $user_id, $args = array() ) {
[88] Fix | Delete
if ( ! empty( $args['name'] ) ) {
[89] Fix | Delete
$args['name'] = sanitize_text_field( $args['name'] );
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
if ( empty( $args['name'] ) ) {
[93] Fix | Delete
return new WP_Error( 'application_password_empty_name', __( 'An application name is required to create an application password.' ), array( 'status' => 400 ) );
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
$new_password = wp_generate_password( static::PW_LENGTH, false );
[97] Fix | Delete
$hashed_password = self::hash_password( $new_password );
[98] Fix | Delete
[99] Fix | Delete
$new_item = array(
[100] Fix | Delete
'uuid' => wp_generate_uuid4(),
[101] Fix | Delete
'app_id' => empty( $args['app_id'] ) ? '' : $args['app_id'],
[102] Fix | Delete
'name' => $args['name'],
[103] Fix | Delete
'password' => $hashed_password,
[104] Fix | Delete
'created' => time(),
[105] Fix | Delete
'last_used' => null,
[106] Fix | Delete
'last_ip' => null,
[107] Fix | Delete
);
[108] Fix | Delete
[109] Fix | Delete
$passwords = static::get_user_application_passwords( $user_id );
[110] Fix | Delete
$passwords[] = $new_item;
[111] Fix | Delete
$saved = static::set_user_application_passwords( $user_id, $passwords );
[112] Fix | Delete
[113] Fix | Delete
if ( ! $saved ) {
[114] Fix | Delete
return new WP_Error( 'db_error', __( 'Could not save application password.' ) );
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
$network_id = get_main_network_id();
[118] Fix | Delete
if ( ! get_network_option( $network_id, self::OPTION_KEY_IN_USE ) ) {
[119] Fix | Delete
update_network_option( $network_id, self::OPTION_KEY_IN_USE, true );
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Fires when an application password is created.
[124] Fix | Delete
*
[125] Fix | Delete
* @since 5.6.0
[126] Fix | Delete
* @since 6.8.0 The hashed password value now uses wp_fast_hash() instead of phpass.
[127] Fix | Delete
*
[128] Fix | Delete
* @param int $user_id The user ID.
[129] Fix | Delete
* @param array $new_item {
[130] Fix | Delete
* The details about the created password.
[131] Fix | Delete
*
[132] Fix | Delete
* @type string $uuid The unique identifier for the application password.
[133] Fix | Delete
* @type string $app_id A UUID provided by the application to uniquely identify it.
[134] Fix | Delete
* @type string $name The name of the application password.
[135] Fix | Delete
* @type string $password A one-way hash of the password.
[136] Fix | Delete
* @type int $created Unix timestamp of when the password was created.
[137] Fix | Delete
* @type null $last_used Null.
[138] Fix | Delete
* @type null $last_ip Null.
[139] Fix | Delete
* }
[140] Fix | Delete
* @param string $new_password The generated application password in plain text.
[141] Fix | Delete
* @param array $args {
[142] Fix | Delete
* Arguments used to create the application password.
[143] Fix | Delete
*
[144] Fix | Delete
* @type string $name The name of the application password.
[145] Fix | Delete
* @type string $app_id A UUID provided by the application to uniquely identify it.
[146] Fix | Delete
* }
[147] Fix | Delete
*/
[148] Fix | Delete
do_action( 'wp_create_application_password', $user_id, $new_item, $new_password, $args );
[149] Fix | Delete
[150] Fix | Delete
return array( $new_password, $new_item );
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
/**
[154] Fix | Delete
* Gets a user's application passwords.
[155] Fix | Delete
*
[156] Fix | Delete
* @since 5.6.0
[157] Fix | Delete
*
[158] Fix | Delete
* @param int $user_id User ID.
[159] Fix | Delete
* @return array {
[160] Fix | Delete
* The list of application passwords.
[161] Fix | Delete
*
[162] Fix | Delete
* @type array ...$0 {
[163] Fix | Delete
* @type string $uuid The unique identifier for the application password.
[164] Fix | Delete
* @type string $app_id A UUID provided by the application to uniquely identify it.
[165] Fix | Delete
* @type string $name The name of the application password.
[166] Fix | Delete
* @type string $password A one-way hash of the password.
[167] Fix | Delete
* @type int $created Unix timestamp of when the password was created.
[168] Fix | Delete
* @type int|null $last_used The Unix timestamp of the GMT date the application password was last used.
[169] Fix | Delete
* @type string|null $last_ip The IP address the application password was last used by.
[170] Fix | Delete
* }
[171] Fix | Delete
* }
[172] Fix | Delete
*/
[173] Fix | Delete
public static function get_user_application_passwords( $user_id ) {
[174] Fix | Delete
$passwords = get_user_meta( $user_id, static::USERMETA_KEY_APPLICATION_PASSWORDS, true );
[175] Fix | Delete
[176] Fix | Delete
if ( ! is_array( $passwords ) ) {
[177] Fix | Delete
return array();
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
$save = false;
[181] Fix | Delete
[182] Fix | Delete
foreach ( $passwords as $i => $password ) {
[183] Fix | Delete
if ( ! isset( $password['uuid'] ) ) {
[184] Fix | Delete
$passwords[ $i ]['uuid'] = wp_generate_uuid4();
[185] Fix | Delete
$save = true;
[186] Fix | Delete
}
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
if ( $save ) {
[190] Fix | Delete
static::set_user_application_passwords( $user_id, $passwords );
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
return $passwords;
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
/**
[197] Fix | Delete
* Gets a user's application password with the given UUID.
[198] Fix | Delete
*
[199] Fix | Delete
* @since 5.6.0
[200] Fix | Delete
*
[201] Fix | Delete
* @param int $user_id User ID.
[202] Fix | Delete
* @param string $uuid The password's UUID.
[203] Fix | Delete
* @return array|null {
[204] Fix | Delete
* The application password if found, null otherwise.
[205] Fix | Delete
*
[206] Fix | Delete
* @type string $uuid The unique identifier for the application password.
[207] Fix | Delete
* @type string $app_id A UUID provided by the application to uniquely identify it.
[208] Fix | Delete
* @type string $name The name of the application password.
[209] Fix | Delete
* @type string $password A one-way hash of the password.
[210] Fix | Delete
* @type int $created Unix timestamp of when the password was created.
[211] Fix | Delete
* @type int|null $last_used The Unix timestamp of the GMT date the application password was last used.
[212] Fix | Delete
* @type string|null $last_ip The IP address the application password was last used by.
[213] Fix | Delete
* }
[214] Fix | Delete
*/
[215] Fix | Delete
public static function get_user_application_password( $user_id, $uuid ) {
[216] Fix | Delete
$passwords = static::get_user_application_passwords( $user_id );
[217] Fix | Delete
[218] Fix | Delete
foreach ( $passwords as $password ) {
[219] Fix | Delete
if ( $password['uuid'] === $uuid ) {
[220] Fix | Delete
return $password;
[221] Fix | Delete
}
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
return null;
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
/**
[228] Fix | Delete
* Checks if an application password with the given name exists for this user.
[229] Fix | Delete
*
[230] Fix | Delete
* @since 5.7.0
[231] Fix | Delete
*
[232] Fix | Delete
* @param int $user_id User ID.
[233] Fix | Delete
* @param string $name Application name.
[234] Fix | Delete
* @return bool Whether the provided application name exists.
[235] Fix | Delete
*/
[236] Fix | Delete
public static function application_name_exists_for_user( $user_id, $name ) {
[237] Fix | Delete
$passwords = static::get_user_application_passwords( $user_id );
[238] Fix | Delete
[239] Fix | Delete
foreach ( $passwords as $password ) {
[240] Fix | Delete
if ( strtolower( $password['name'] ) === strtolower( $name ) ) {
[241] Fix | Delete
return true;
[242] Fix | Delete
}
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
return false;
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
/**
[249] Fix | Delete
* Updates an application password.
[250] Fix | Delete
*
[251] Fix | Delete
* @since 5.6.0
[252] Fix | Delete
* @since 6.8.0 The actual password should now be hashed using wp_fast_hash().
[253] Fix | Delete
*
[254] Fix | Delete
* @param int $user_id User ID.
[255] Fix | Delete
* @param string $uuid The password's UUID.
[256] Fix | Delete
* @param array $update {
[257] Fix | Delete
* Information about the application password to update.
[258] Fix | Delete
*
[259] Fix | Delete
* @type string $uuid The unique identifier for the application password.
[260] Fix | Delete
* @type string $app_id A UUID provided by the application to uniquely identify it.
[261] Fix | Delete
* @type string $name The name of the application password.
[262] Fix | Delete
* @type string $password A one-way hash of the password.
[263] Fix | Delete
* @type int $created Unix timestamp of when the password was created.
[264] Fix | Delete
* @type int|null $last_used The Unix timestamp of the GMT date the application password was last used.
[265] Fix | Delete
* @type string|null $last_ip The IP address the application password was last used by.
[266] Fix | Delete
* }
[267] Fix | Delete
* @return true|WP_Error True if successful, otherwise a WP_Error instance is returned on error.
[268] Fix | Delete
*/
[269] Fix | Delete
public static function update_application_password( $user_id, $uuid, $update = array() ) {
[270] Fix | Delete
$passwords = static::get_user_application_passwords( $user_id );
[271] Fix | Delete
[272] Fix | Delete
foreach ( $passwords as &$item ) {
[273] Fix | Delete
if ( $item['uuid'] !== $uuid ) {
[274] Fix | Delete
continue;
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
if ( ! empty( $update['name'] ) ) {
[278] Fix | Delete
$update['name'] = sanitize_text_field( $update['name'] );
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
$save = false;
[282] Fix | Delete
[283] Fix | Delete
if ( ! empty( $update['name'] ) && $item['name'] !== $update['name'] ) {
[284] Fix | Delete
$item['name'] = $update['name'];
[285] Fix | Delete
$save = true;
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
if ( $save ) {
[289] Fix | Delete
$saved = static::set_user_application_passwords( $user_id, $passwords );
[290] Fix | Delete
[291] Fix | Delete
if ( ! $saved ) {
[292] Fix | Delete
return new WP_Error( 'db_error', __( 'Could not save application password.' ) );
[293] Fix | Delete
}
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
/**
[297] Fix | Delete
* Fires when an application password is updated.
[298] Fix | Delete
*
[299] Fix | Delete
* @since 5.6.0
[300] Fix | Delete
* @since 6.8.0 The password is now hashed using wp_fast_hash() instead of phpass.
[301] Fix | Delete
* Existing passwords may still be hashed using phpass.
[302] Fix | Delete
*
[303] Fix | Delete
* @param int $user_id The user ID.
[304] Fix | Delete
* @param array $item {
[305] Fix | Delete
* The updated application password details.
[306] Fix | Delete
*
[307] Fix | Delete
* @type string $uuid The unique identifier for the application password.
[308] Fix | Delete
* @type string $app_id A UUID provided by the application to uniquely identify it.
[309] Fix | Delete
* @type string $name The name of the application password.
[310] Fix | Delete
* @type string $password A one-way hash of the password.
[311] Fix | Delete
* @type int $created Unix timestamp of when the password was created.
[312] Fix | Delete
* @type int|null $last_used The Unix timestamp of the GMT date the application password was last used.
[313] Fix | Delete
* @type string|null $last_ip The IP address the application password was last used by.
[314] Fix | Delete
* }
[315] Fix | Delete
* @param array $update The information to update.
[316] Fix | Delete
*/
[317] Fix | Delete
do_action( 'wp_update_application_password', $user_id, $item, $update );
[318] Fix | Delete
[319] Fix | Delete
return true;
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
return new WP_Error( 'application_password_not_found', __( 'Could not find an application password with that id.' ) );
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
/**
[326] Fix | Delete
* Records that an application password has been used.
[327] Fix | Delete
*
[328] Fix | Delete
* @since 5.6.0
[329] Fix | Delete
*
[330] Fix | Delete
* @param int $user_id User ID.
[331] Fix | Delete
* @param string $uuid The password's UUID.
[332] Fix | Delete
* @return true|WP_Error True if the usage was recorded, a WP_Error if an error occurs.
[333] Fix | Delete
*/
[334] Fix | Delete
public static function record_application_password_usage( $user_id, $uuid ) {
[335] Fix | Delete
$passwords = static::get_user_application_passwords( $user_id );
[336] Fix | Delete
[337] Fix | Delete
foreach ( $passwords as &$password ) {
[338] Fix | Delete
if ( $password['uuid'] !== $uuid ) {
[339] Fix | Delete
continue;
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
// Only record activity once a day.
[343] Fix | Delete
if ( $password['last_used'] + DAY_IN_SECONDS > time() ) {
[344] Fix | Delete
return true;
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
$password['last_used'] = time();
[348] Fix | Delete
$password['last_ip'] = $_SERVER['REMOTE_ADDR'];
[349] Fix | Delete
[350] Fix | Delete
$saved = static::set_user_application_passwords( $user_id, $passwords );
[351] Fix | Delete
[352] Fix | Delete
if ( ! $saved ) {
[353] Fix | Delete
return new WP_Error( 'db_error', __( 'Could not save application password.' ) );
[354] Fix | Delete
}
[355] Fix | Delete
[356] Fix | Delete
return true;
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
// Specified application password not found!
[360] Fix | Delete
return new WP_Error( 'application_password_not_found', __( 'Could not find an application password with that id.' ) );
[361] Fix | Delete
}
[362] Fix | Delete
[363] Fix | Delete
/**
[364] Fix | Delete
* Deletes an application password.
[365] Fix | Delete
*
[366] Fix | Delete
* @since 5.6.0
[367] Fix | Delete
*
[368] Fix | Delete
* @param int $user_id User ID.
[369] Fix | Delete
* @param string $uuid The password's UUID.
[370] Fix | Delete
* @return true|WP_Error Whether the password was successfully found and deleted, a WP_Error otherwise.
[371] Fix | Delete
*/
[372] Fix | Delete
public static function delete_application_password( $user_id, $uuid ) {
[373] Fix | Delete
$passwords = static::get_user_application_passwords( $user_id );
[374] Fix | Delete
[375] Fix | Delete
foreach ( $passwords as $key => $item ) {
[376] Fix | Delete
if ( $item['uuid'] === $uuid ) {
[377] Fix | Delete
unset( $passwords[ $key ] );
[378] Fix | Delete
$saved = static::set_user_application_passwords( $user_id, $passwords );
[379] Fix | Delete
[380] Fix | Delete
if ( ! $saved ) {
[381] Fix | Delete
return new WP_Error( 'db_error', __( 'Could not delete application password.' ) );
[382] Fix | Delete
}
[383] Fix | Delete
[384] Fix | Delete
/**
[385] Fix | Delete
* Fires when an application password is deleted.
[386] Fix | Delete
*
[387] Fix | Delete
* @since 5.6.0
[388] Fix | Delete
*
[389] Fix | Delete
* @param int $user_id The user ID.
[390] Fix | Delete
* @param array $item The data about the application password.
[391] Fix | Delete
*/
[392] Fix | Delete
do_action( 'wp_delete_application_password', $user_id, $item );
[393] Fix | Delete
[394] Fix | Delete
return true;
[395] Fix | Delete
}
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
return new WP_Error( 'application_password_not_found', __( 'Could not find an application password with that id.' ) );
[399] Fix | Delete
}
[400] Fix | Delete
[401] Fix | Delete
/**
[402] Fix | Delete
* Deletes all application passwords for the given user.
[403] Fix | Delete
*
[404] Fix | Delete
* @since 5.6.0
[405] Fix | Delete
*
[406] Fix | Delete
* @param int $user_id User ID.
[407] Fix | Delete
* @return int|WP_Error The number of passwords that were deleted or a WP_Error on failure.
[408] Fix | Delete
*/
[409] Fix | Delete
public static function delete_all_application_passwords( $user_id ) {
[410] Fix | Delete
$passwords = static::get_user_application_passwords( $user_id );
[411] Fix | Delete
[412] Fix | Delete
if ( $passwords ) {
[413] Fix | Delete
$saved = static::set_user_application_passwords( $user_id, array() );
[414] Fix | Delete
[415] Fix | Delete
if ( ! $saved ) {
[416] Fix | Delete
return new WP_Error( 'db_error', __( 'Could not delete application passwords.' ) );
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
foreach ( $passwords as $item ) {
[420] Fix | Delete
/** This action is documented in wp-includes/class-wp-application-passwords.php */
[421] Fix | Delete
do_action( 'wp_delete_application_password', $user_id, $item );
[422] Fix | Delete
}
[423] Fix | Delete
[424] Fix | Delete
return count( $passwords );
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
return 0;
[428] Fix | Delete
}
[429] Fix | Delete
[430] Fix | Delete
/**
[431] Fix | Delete
* Sets a user's application passwords.
[432] Fix | Delete
*
[433] Fix | Delete
* @since 5.6.0
[434] Fix | Delete
*
[435] Fix | Delete
* @param int $user_id User ID.
[436] Fix | Delete
* @param array $passwords {
[437] Fix | Delete
* The list of application passwords.
[438] Fix | Delete
*
[439] Fix | Delete
* @type array ...$0 {
[440] Fix | Delete
* @type string $uuid The unique identifier for the application password.
[441] Fix | Delete
* @type string $app_id A UUID provided by the application to uniquely identify it.
[442] Fix | Delete
* @type string $name The name of the application password.
[443] Fix | Delete
* @type string $password A one-way hash of the password.
[444] Fix | Delete
* @type int $created Unix timestamp of when the password was created.
[445] Fix | Delete
* @type int|null $last_used The Unix timestamp of the GMT date the application password was last used.
[446] Fix | Delete
* @type string|null $last_ip The IP address the application password was last used by.
[447] Fix | Delete
* }
[448] Fix | Delete
* }
[449] Fix | Delete
* @return int|bool User meta ID if the key didn't exist (ie. this is the first time that an application password
[450] Fix | Delete
* has been saved for the user), true on successful update, false on failure or if the value passed
[451] Fix | Delete
* is the same as the one that is already in the database.
[452] Fix | Delete
*/
[453] Fix | Delete
protected static function set_user_application_passwords( $user_id, $passwords ) {
[454] Fix | Delete
return update_user_meta( $user_id, static::USERMETA_KEY_APPLICATION_PASSWORDS, $passwords );
[455] Fix | Delete
}
[456] Fix | Delete
[457] Fix | Delete
/**
[458] Fix | Delete
* Sanitizes and then splits a password into smaller chunks.
[459] Fix | Delete
*
[460] Fix | Delete
* @since 5.6.0
[461] Fix | Delete
*
[462] Fix | Delete
* @param string $raw_password The raw application password.
[463] Fix | Delete
* @return string The chunked password.
[464] Fix | Delete
*/
[465] Fix | Delete
public static function chunk_password(
[466] Fix | Delete
#[\SensitiveParameter]
[467] Fix | Delete
$raw_password
[468] Fix | Delete
) {
[469] Fix | Delete
$raw_password = preg_replace( '/[^a-z\d]/i', '', $raw_password );
[470] Fix | Delete
[471] Fix | Delete
return trim( chunk_split( $raw_password, 4, ' ' ) );
[472] Fix | Delete
}
[473] Fix | Delete
[474] Fix | Delete
/**
[475] Fix | Delete
* Hashes a plaintext application password.
[476] Fix | Delete
*
[477] Fix | Delete
* @since 6.8.0
[478] Fix | Delete
*
[479] Fix | Delete
* @param string $password Plaintext password.
[480] Fix | Delete
* @return string Hashed password.
[481] Fix | Delete
*/
[482] Fix | Delete
public static function hash_password(
[483] Fix | Delete
#[\SensitiveParameter]
[484] Fix | Delete
string $password
[485] Fix | Delete
): string {
[486] Fix | Delete
return wp_fast_hash( $password );
[487] Fix | Delete
}
[488] Fix | Delete
[489] Fix | Delete
/**
[490] Fix | Delete
* Checks a plaintext application password against a hashed password.
[491] Fix | Delete
*
[492] Fix | Delete
* @since 6.8.0
[493] Fix | Delete
*
[494] Fix | Delete
* @param string $password Plaintext password.
[495] Fix | Delete
* @param string $hash Hash of the password to check against.
[496] Fix | Delete
* @return bool Whether the password matches the hashed password.
[497] Fix | Delete
*/
[498] Fix | Delete
public static function check_password(
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function