Edit File by line
/home/barbar84/www/wp-inclu...
File: pluggable.php
* @since 4.6.0 The `$notify` parameter accepts 'user' for sending notification only to the user created.
[2000] Fix | Delete
*
[2001] Fix | Delete
* @param int $user_id User ID.
[2002] Fix | Delete
* @param null $deprecated Not used (argument deprecated).
[2003] Fix | Delete
* @param string $notify Optional. Type of notification that should happen. Accepts 'admin' or an empty
[2004] Fix | Delete
* string (admin only), 'user', or 'both' (admin and user). Default empty.
[2005] Fix | Delete
*/
[2006] Fix | Delete
function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ) {
[2007] Fix | Delete
if ( null !== $deprecated ) {
[2008] Fix | Delete
_deprecated_argument( __FUNCTION__, '4.3.1' );
[2009] Fix | Delete
}
[2010] Fix | Delete
[2011] Fix | Delete
// Accepts only 'user', 'admin' , 'both' or default '' as $notify.
[2012] Fix | Delete
if ( ! in_array( $notify, array( 'user', 'admin', 'both', '' ), true ) ) {
[2013] Fix | Delete
return;
[2014] Fix | Delete
}
[2015] Fix | Delete
[2016] Fix | Delete
$user = get_userdata( $user_id );
[2017] Fix | Delete
[2018] Fix | Delete
// The blogname option is escaped with esc_html() on the way into the database in sanitize_option().
[2019] Fix | Delete
// We want to reverse this for the plain text arena of emails.
[2020] Fix | Delete
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
[2021] Fix | Delete
[2022] Fix | Delete
if ( 'user' !== $notify ) {
[2023] Fix | Delete
$switched_locale = switch_to_locale( get_locale() );
[2024] Fix | Delete
[2025] Fix | Delete
/* translators: %s: Site title. */
[2026] Fix | Delete
$message = sprintf( __( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n";
[2027] Fix | Delete
/* translators: %s: User login. */
[2028] Fix | Delete
$message .= sprintf( __( 'Username: %s' ), $user->user_login ) . "\r\n\r\n";
[2029] Fix | Delete
/* translators: %s: User email address. */
[2030] Fix | Delete
$message .= sprintf( __( 'Email: %s' ), $user->user_email ) . "\r\n";
[2031] Fix | Delete
[2032] Fix | Delete
$wp_new_user_notification_email_admin = array(
[2033] Fix | Delete
'to' => get_option( 'admin_email' ),
[2034] Fix | Delete
/* translators: New user registration notification email subject. %s: Site title. */
[2035] Fix | Delete
'subject' => __( '[%s] New User Registration' ),
[2036] Fix | Delete
'message' => $message,
[2037] Fix | Delete
'headers' => '',
[2038] Fix | Delete
);
[2039] Fix | Delete
[2040] Fix | Delete
/**
[2041] Fix | Delete
* Filters the contents of the new user notification email sent to the site admin.
[2042] Fix | Delete
*
[2043] Fix | Delete
* @since 4.9.0
[2044] Fix | Delete
*
[2045] Fix | Delete
* @param array $wp_new_user_notification_email_admin {
[2046] Fix | Delete
* Used to build wp_mail().
[2047] Fix | Delete
*
[2048] Fix | Delete
* @type string $to The intended recipient - site admin email address.
[2049] Fix | Delete
* @type string $subject The subject of the email.
[2050] Fix | Delete
* @type string $message The body of the email.
[2051] Fix | Delete
* @type string $headers The headers of the email.
[2052] Fix | Delete
* }
[2053] Fix | Delete
* @param WP_User $user User object for new user.
[2054] Fix | Delete
* @param string $blogname The site title.
[2055] Fix | Delete
*/
[2056] Fix | Delete
$wp_new_user_notification_email_admin = apply_filters( 'wp_new_user_notification_email_admin', $wp_new_user_notification_email_admin, $user, $blogname );
[2057] Fix | Delete
[2058] Fix | Delete
wp_mail(
[2059] Fix | Delete
$wp_new_user_notification_email_admin['to'],
[2060] Fix | Delete
wp_specialchars_decode( sprintf( $wp_new_user_notification_email_admin['subject'], $blogname ) ),
[2061] Fix | Delete
$wp_new_user_notification_email_admin['message'],
[2062] Fix | Delete
$wp_new_user_notification_email_admin['headers']
[2063] Fix | Delete
);
[2064] Fix | Delete
[2065] Fix | Delete
if ( $switched_locale ) {
[2066] Fix | Delete
restore_previous_locale();
[2067] Fix | Delete
}
[2068] Fix | Delete
}
[2069] Fix | Delete
[2070] Fix | Delete
// `$deprecated` was pre-4.3 `$plaintext_pass`. An empty `$plaintext_pass` didn't sent a user notification.
[2071] Fix | Delete
if ( 'admin' === $notify || ( empty( $deprecated ) && empty( $notify ) ) ) {
[2072] Fix | Delete
return;
[2073] Fix | Delete
}
[2074] Fix | Delete
[2075] Fix | Delete
$key = get_password_reset_key( $user );
[2076] Fix | Delete
if ( is_wp_error( $key ) ) {
[2077] Fix | Delete
return;
[2078] Fix | Delete
}
[2079] Fix | Delete
[2080] Fix | Delete
$switched_locale = switch_to_locale( get_user_locale( $user ) );
[2081] Fix | Delete
[2082] Fix | Delete
/* translators: %s: User login. */
[2083] Fix | Delete
$message = sprintf( __( 'Username: %s' ), $user->user_login ) . "\r\n\r\n";
[2084] Fix | Delete
$message .= __( 'To set your password, visit the following address:' ) . "\r\n\r\n";
[2085] Fix | Delete
$message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user->user_login ), 'login' ) . "\r\n\r\n";
[2086] Fix | Delete
[2087] Fix | Delete
$message .= wp_login_url() . "\r\n";
[2088] Fix | Delete
[2089] Fix | Delete
$wp_new_user_notification_email = array(
[2090] Fix | Delete
'to' => $user->user_email,
[2091] Fix | Delete
/* translators: Login details notification email subject. %s: Site title. */
[2092] Fix | Delete
'subject' => __( '[%s] Login Details' ),
[2093] Fix | Delete
'message' => $message,
[2094] Fix | Delete
'headers' => '',
[2095] Fix | Delete
);
[2096] Fix | Delete
[2097] Fix | Delete
/**
[2098] Fix | Delete
* Filters the contents of the new user notification email sent to the new user.
[2099] Fix | Delete
*
[2100] Fix | Delete
* @since 4.9.0
[2101] Fix | Delete
*
[2102] Fix | Delete
* @param array $wp_new_user_notification_email {
[2103] Fix | Delete
* Used to build wp_mail().
[2104] Fix | Delete
*
[2105] Fix | Delete
* @type string $to The intended recipient - New user email address.
[2106] Fix | Delete
* @type string $subject The subject of the email.
[2107] Fix | Delete
* @type string $message The body of the email.
[2108] Fix | Delete
* @type string $headers The headers of the email.
[2109] Fix | Delete
* }
[2110] Fix | Delete
* @param WP_User $user User object for new user.
[2111] Fix | Delete
* @param string $blogname The site title.
[2112] Fix | Delete
*/
[2113] Fix | Delete
$wp_new_user_notification_email = apply_filters( 'wp_new_user_notification_email', $wp_new_user_notification_email, $user, $blogname );
[2114] Fix | Delete
[2115] Fix | Delete
wp_mail(
[2116] Fix | Delete
$wp_new_user_notification_email['to'],
[2117] Fix | Delete
wp_specialchars_decode( sprintf( $wp_new_user_notification_email['subject'], $blogname ) ),
[2118] Fix | Delete
$wp_new_user_notification_email['message'],
[2119] Fix | Delete
$wp_new_user_notification_email['headers']
[2120] Fix | Delete
);
[2121] Fix | Delete
[2122] Fix | Delete
if ( $switched_locale ) {
[2123] Fix | Delete
restore_previous_locale();
[2124] Fix | Delete
}
[2125] Fix | Delete
}
[2126] Fix | Delete
endif;
[2127] Fix | Delete
[2128] Fix | Delete
if ( ! function_exists( 'wp_nonce_tick' ) ) :
[2129] Fix | Delete
/**
[2130] Fix | Delete
* Returns the time-dependent variable for nonce creation.
[2131] Fix | Delete
*
[2132] Fix | Delete
* A nonce has a lifespan of two ticks. Nonces in their second tick may be
[2133] Fix | Delete
* updated, e.g. by autosave.
[2134] Fix | Delete
*
[2135] Fix | Delete
* @since 2.5.0
[2136] Fix | Delete
*
[2137] Fix | Delete
* @return float Float value rounded up to the next highest integer.
[2138] Fix | Delete
*/
[2139] Fix | Delete
function wp_nonce_tick() {
[2140] Fix | Delete
/**
[2141] Fix | Delete
* Filters the lifespan of nonces in seconds.
[2142] Fix | Delete
*
[2143] Fix | Delete
* @since 2.5.0
[2144] Fix | Delete
*
[2145] Fix | Delete
* @param int $lifespan Lifespan of nonces in seconds. Default 86,400 seconds, or one day.
[2146] Fix | Delete
*/
[2147] Fix | Delete
$nonce_life = apply_filters( 'nonce_life', DAY_IN_SECONDS );
[2148] Fix | Delete
[2149] Fix | Delete
return ceil( time() / ( $nonce_life / 2 ) );
[2150] Fix | Delete
}
[2151] Fix | Delete
endif;
[2152] Fix | Delete
[2153] Fix | Delete
if ( ! function_exists( 'wp_verify_nonce' ) ) :
[2154] Fix | Delete
/**
[2155] Fix | Delete
* Verifies that a correct security nonce was used with time limit.
[2156] Fix | Delete
*
[2157] Fix | Delete
* A nonce is valid for 24 hours (by default).
[2158] Fix | Delete
*
[2159] Fix | Delete
* @since 2.0.3
[2160] Fix | Delete
*
[2161] Fix | Delete
* @param string $nonce Nonce value that was used for verification, usually via a form field.
[2162] Fix | Delete
* @param string|int $action Should give context to what is taking place and be the same when nonce was created.
[2163] Fix | Delete
* @return int|false 1 if the nonce is valid and generated between 0-12 hours ago,
[2164] Fix | Delete
* 2 if the nonce is valid and generated between 12-24 hours ago.
[2165] Fix | Delete
* False if the nonce is invalid.
[2166] Fix | Delete
*/
[2167] Fix | Delete
function wp_verify_nonce( $nonce, $action = -1 ) {
[2168] Fix | Delete
$nonce = (string) $nonce;
[2169] Fix | Delete
$user = wp_get_current_user();
[2170] Fix | Delete
$uid = (int) $user->ID;
[2171] Fix | Delete
if ( ! $uid ) {
[2172] Fix | Delete
/**
[2173] Fix | Delete
* Filters whether the user who generated the nonce is logged out.
[2174] Fix | Delete
*
[2175] Fix | Delete
* @since 3.5.0
[2176] Fix | Delete
*
[2177] Fix | Delete
* @param int $uid ID of the nonce-owning user.
[2178] Fix | Delete
* @param string $action The nonce action.
[2179] Fix | Delete
*/
[2180] Fix | Delete
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
[2181] Fix | Delete
}
[2182] Fix | Delete
[2183] Fix | Delete
if ( empty( $nonce ) ) {
[2184] Fix | Delete
return false;
[2185] Fix | Delete
}
[2186] Fix | Delete
[2187] Fix | Delete
$token = wp_get_session_token();
[2188] Fix | Delete
$i = wp_nonce_tick();
[2189] Fix | Delete
[2190] Fix | Delete
// Nonce generated 0-12 hours ago.
[2191] Fix | Delete
$expected = substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
[2192] Fix | Delete
if ( hash_equals( $expected, $nonce ) ) {
[2193] Fix | Delete
return 1;
[2194] Fix | Delete
}
[2195] Fix | Delete
[2196] Fix | Delete
// Nonce generated 12-24 hours ago.
[2197] Fix | Delete
$expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
[2198] Fix | Delete
if ( hash_equals( $expected, $nonce ) ) {
[2199] Fix | Delete
return 2;
[2200] Fix | Delete
}
[2201] Fix | Delete
[2202] Fix | Delete
/**
[2203] Fix | Delete
* Fires when nonce verification fails.
[2204] Fix | Delete
*
[2205] Fix | Delete
* @since 4.4.0
[2206] Fix | Delete
*
[2207] Fix | Delete
* @param string $nonce The invalid nonce.
[2208] Fix | Delete
* @param string|int $action The nonce action.
[2209] Fix | Delete
* @param WP_User $user The current user object.
[2210] Fix | Delete
* @param string $token The user's session token.
[2211] Fix | Delete
*/
[2212] Fix | Delete
do_action( 'wp_verify_nonce_failed', $nonce, $action, $user, $token );
[2213] Fix | Delete
[2214] Fix | Delete
// Invalid nonce.
[2215] Fix | Delete
return false;
[2216] Fix | Delete
}
[2217] Fix | Delete
endif;
[2218] Fix | Delete
[2219] Fix | Delete
if ( ! function_exists( 'wp_create_nonce' ) ) :
[2220] Fix | Delete
/**
[2221] Fix | Delete
* Creates a cryptographic token tied to a specific action, user, user session,
[2222] Fix | Delete
* and window of time.
[2223] Fix | Delete
*
[2224] Fix | Delete
* @since 2.0.3
[2225] Fix | Delete
* @since 4.0.0 Session tokens were integrated with nonce creation
[2226] Fix | Delete
*
[2227] Fix | Delete
* @param string|int $action Scalar value to add context to the nonce.
[2228] Fix | Delete
* @return string The token.
[2229] Fix | Delete
*/
[2230] Fix | Delete
function wp_create_nonce( $action = -1 ) {
[2231] Fix | Delete
$user = wp_get_current_user();
[2232] Fix | Delete
$uid = (int) $user->ID;
[2233] Fix | Delete
if ( ! $uid ) {
[2234] Fix | Delete
/** This filter is documented in wp-includes/pluggable.php */
[2235] Fix | Delete
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
[2236] Fix | Delete
}
[2237] Fix | Delete
[2238] Fix | Delete
$token = wp_get_session_token();
[2239] Fix | Delete
$i = wp_nonce_tick();
[2240] Fix | Delete
[2241] Fix | Delete
return substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
[2242] Fix | Delete
}
[2243] Fix | Delete
endif;
[2244] Fix | Delete
[2245] Fix | Delete
if ( ! function_exists( 'wp_salt' ) ) :
[2246] Fix | Delete
/**
[2247] Fix | Delete
* Returns a salt to add to hashes.
[2248] Fix | Delete
*
[2249] Fix | Delete
* Salts are created using secret keys. Secret keys are located in two places:
[2250] Fix | Delete
* in the database and in the wp-config.php file. The secret key in the database
[2251] Fix | Delete
* is randomly generated and will be appended to the secret keys in wp-config.php.
[2252] Fix | Delete
*
[2253] Fix | Delete
* The secret keys in wp-config.php should be updated to strong, random keys to maximize
[2254] Fix | Delete
* security. Below is an example of how the secret key constants are defined.
[2255] Fix | Delete
* Do not paste this example directly into wp-config.php. Instead, have a
[2256] Fix | Delete
* {@link https://api.wordpress.org/secret-key/1.1/salt/ secret key created} just
[2257] Fix | Delete
* for you.
[2258] Fix | Delete
*
[2259] Fix | Delete
* define('AUTH_KEY', ' Xakm<o xQy rw4EMsLKM-?!T+,PFF})H4lzcW57AF0U@N@< >M%G4Yt>f`z]MON');
[2260] Fix | Delete
* define('SECURE_AUTH_KEY', 'LzJ}op]mr|6+![P}Ak:uNdJCJZd>(Hx.-Mh#Tz)pCIU#uGEnfFz|f ;;eU%/U^O~');
[2261] Fix | Delete
* define('LOGGED_IN_KEY', '|i|Ux`9<p-h$aFf(qnT:sDO:D1P^wZ$$/Ra@miTJi9G;ddp_<q}6H1)o|a +&JCM');
[2262] Fix | Delete
* define('NONCE_KEY', '%:R{[P|,s.KuMltH5}cI;/k<Gx~j!f0I)m_sIyu+&NJZ)-iO>z7X>QYR0Z_XnZ@|');
[2263] Fix | Delete
* define('AUTH_SALT', 'eZyT)-Naw]F8CwA*VaW#q*|.)g@o}||wf~@C-YSt}(dh_r6EbI#A,y|nU2{B#JBW');
[2264] Fix | Delete
* define('SECURE_AUTH_SALT', '!=oLUTXh,QW=H `}`L|9/^4-3 STz},T(w}W<I`.JjPi)<Bmf1v,HpGe}T1:Xt7n');
[2265] Fix | Delete
* define('LOGGED_IN_SALT', '+XSqHc;@Q*K_b|Z?NC[3H!!EONbh.n<+=uKR:>*c(u`g~EJBf#8u#R{mUEZrozmm');
[2266] Fix | Delete
* define('NONCE_SALT', 'h`GXHhD>SLWVfg1(1(N{;.V!MoE(SfbA_ksP@&`+AycHcAV$+?@3q+rxV{%^VyKT');
[2267] Fix | Delete
*
[2268] Fix | Delete
* Salting passwords helps against tools which has stored hashed values of
[2269] Fix | Delete
* common dictionary strings. The added values makes it harder to crack.
[2270] Fix | Delete
*
[2271] Fix | Delete
* @since 2.5.0
[2272] Fix | Delete
*
[2273] Fix | Delete
* @link https://api.wordpress.org/secret-key/1.1/salt/ Create secrets for wp-config.php
[2274] Fix | Delete
*
[2275] Fix | Delete
* @param string $scheme Authentication scheme (auth, secure_auth, logged_in, nonce)
[2276] Fix | Delete
* @return string Salt value
[2277] Fix | Delete
*/
[2278] Fix | Delete
function wp_salt( $scheme = 'auth' ) {
[2279] Fix | Delete
static $cached_salts = array();
[2280] Fix | Delete
if ( isset( $cached_salts[ $scheme ] ) ) {
[2281] Fix | Delete
/**
[2282] Fix | Delete
* Filters the WordPress salt.
[2283] Fix | Delete
*
[2284] Fix | Delete
* @since 2.5.0
[2285] Fix | Delete
*
[2286] Fix | Delete
* @param string $cached_salt Cached salt for the given scheme.
[2287] Fix | Delete
* @param string $scheme Authentication scheme. Values include 'auth',
[2288] Fix | Delete
* 'secure_auth', 'logged_in', and 'nonce'.
[2289] Fix | Delete
*/
[2290] Fix | Delete
return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme );
[2291] Fix | Delete
}
[2292] Fix | Delete
[2293] Fix | Delete
static $duplicated_keys;
[2294] Fix | Delete
if ( null === $duplicated_keys ) {
[2295] Fix | Delete
$duplicated_keys = array( 'put your unique phrase here' => true );
[2296] Fix | Delete
foreach ( array( 'AUTH', 'SECURE_AUTH', 'LOGGED_IN', 'NONCE', 'SECRET' ) as $first ) {
[2297] Fix | Delete
foreach ( array( 'KEY', 'SALT' ) as $second ) {
[2298] Fix | Delete
if ( ! defined( "{$first}_{$second}" ) ) {
[2299] Fix | Delete
continue;
[2300] Fix | Delete
}
[2301] Fix | Delete
$value = constant( "{$first}_{$second}" );
[2302] Fix | Delete
$duplicated_keys[ $value ] = isset( $duplicated_keys[ $value ] );
[2303] Fix | Delete
}
[2304] Fix | Delete
}
[2305] Fix | Delete
}
[2306] Fix | Delete
[2307] Fix | Delete
$values = array(
[2308] Fix | Delete
'key' => '',
[2309] Fix | Delete
'salt' => '',
[2310] Fix | Delete
);
[2311] Fix | Delete
if ( defined( 'SECRET_KEY' ) && SECRET_KEY && empty( $duplicated_keys[ SECRET_KEY ] ) ) {
[2312] Fix | Delete
$values['key'] = SECRET_KEY;
[2313] Fix | Delete
}
[2314] Fix | Delete
if ( 'auth' === $scheme && defined( 'SECRET_SALT' ) && SECRET_SALT && empty( $duplicated_keys[ SECRET_SALT ] ) ) {
[2315] Fix | Delete
$values['salt'] = SECRET_SALT;
[2316] Fix | Delete
}
[2317] Fix | Delete
[2318] Fix | Delete
if ( in_array( $scheme, array( 'auth', 'secure_auth', 'logged_in', 'nonce' ), true ) ) {
[2319] Fix | Delete
foreach ( array( 'key', 'salt' ) as $type ) {
[2320] Fix | Delete
$const = strtoupper( "{$scheme}_{$type}" );
[2321] Fix | Delete
if ( defined( $const ) && constant( $const ) && empty( $duplicated_keys[ constant( $const ) ] ) ) {
[2322] Fix | Delete
$values[ $type ] = constant( $const );
[2323] Fix | Delete
} elseif ( ! $values[ $type ] ) {
[2324] Fix | Delete
$values[ $type ] = get_site_option( "{$scheme}_{$type}" );
[2325] Fix | Delete
if ( ! $values[ $type ] ) {
[2326] Fix | Delete
$values[ $type ] = wp_generate_password( 64, true, true );
[2327] Fix | Delete
update_site_option( "{$scheme}_{$type}", $values[ $type ] );
[2328] Fix | Delete
}
[2329] Fix | Delete
}
[2330] Fix | Delete
}
[2331] Fix | Delete
} else {
[2332] Fix | Delete
if ( ! $values['key'] ) {
[2333] Fix | Delete
$values['key'] = get_site_option( 'secret_key' );
[2334] Fix | Delete
if ( ! $values['key'] ) {
[2335] Fix | Delete
$values['key'] = wp_generate_password( 64, true, true );
[2336] Fix | Delete
update_site_option( 'secret_key', $values['key'] );
[2337] Fix | Delete
}
[2338] Fix | Delete
}
[2339] Fix | Delete
$values['salt'] = hash_hmac( 'md5', $scheme, $values['key'] );
[2340] Fix | Delete
}
[2341] Fix | Delete
[2342] Fix | Delete
$cached_salts[ $scheme ] = $values['key'] . $values['salt'];
[2343] Fix | Delete
[2344] Fix | Delete
/** This filter is documented in wp-includes/pluggable.php */
[2345] Fix | Delete
return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme );
[2346] Fix | Delete
}
[2347] Fix | Delete
endif;
[2348] Fix | Delete
[2349] Fix | Delete
if ( ! function_exists( 'wp_hash' ) ) :
[2350] Fix | Delete
/**
[2351] Fix | Delete
* Get hash of given string.
[2352] Fix | Delete
*
[2353] Fix | Delete
* @since 2.0.3
[2354] Fix | Delete
*
[2355] Fix | Delete
* @param string $data Plain text to hash
[2356] Fix | Delete
* @param string $scheme Authentication scheme (auth, secure_auth, logged_in, nonce)
[2357] Fix | Delete
* @return string Hash of $data
[2358] Fix | Delete
*/
[2359] Fix | Delete
function wp_hash( $data, $scheme = 'auth' ) {
[2360] Fix | Delete
$salt = wp_salt( $scheme );
[2361] Fix | Delete
[2362] Fix | Delete
return hash_hmac( 'md5', $data, $salt );
[2363] Fix | Delete
}
[2364] Fix | Delete
endif;
[2365] Fix | Delete
[2366] Fix | Delete
if ( ! function_exists( 'wp_hash_password' ) ) :
[2367] Fix | Delete
/**
[2368] Fix | Delete
* Create a hash (encrypt) of a plain text password.
[2369] Fix | Delete
*
[2370] Fix | Delete
* For integration with other applications, this function can be overwritten to
[2371] Fix | Delete
* instead use the other package password checking algorithm.
[2372] Fix | Delete
*
[2373] Fix | Delete
* @since 2.5.0
[2374] Fix | Delete
*
[2375] Fix | Delete
* @global PasswordHash $wp_hasher PHPass object
[2376] Fix | Delete
*
[2377] Fix | Delete
* @param string $password Plain text user password to hash
[2378] Fix | Delete
* @return string The hash string of the password
[2379] Fix | Delete
*/
[2380] Fix | Delete
function wp_hash_password( $password ) {
[2381] Fix | Delete
global $wp_hasher;
[2382] Fix | Delete
[2383] Fix | Delete
if ( empty( $wp_hasher ) ) {
[2384] Fix | Delete
require_once ABSPATH . WPINC . '/class-phpass.php';
[2385] Fix | Delete
// By default, use the portable hash from phpass.
[2386] Fix | Delete
$wp_hasher = new PasswordHash( 8, true );
[2387] Fix | Delete
}
[2388] Fix | Delete
[2389] Fix | Delete
return $wp_hasher->HashPassword( trim( $password ) );
[2390] Fix | Delete
}
[2391] Fix | Delete
endif;
[2392] Fix | Delete
[2393] Fix | Delete
if ( ! function_exists( 'wp_check_password' ) ) :
[2394] Fix | Delete
/**
[2395] Fix | Delete
* Checks the plaintext password against the encrypted Password.
[2396] Fix | Delete
*
[2397] Fix | Delete
* Maintains compatibility between old version and the new cookie authentication
[2398] Fix | Delete
* protocol using PHPass library. The $hash parameter is the encrypted password
[2399] Fix | Delete
* and the function compares the plain text password when encrypted similarly
[2400] Fix | Delete
* against the already encrypted password to see if they match.
[2401] Fix | Delete
*
[2402] Fix | Delete
* For integration with other applications, this function can be overwritten to
[2403] Fix | Delete
* instead use the other package password checking algorithm.
[2404] Fix | Delete
*
[2405] Fix | Delete
* @since 2.5.0
[2406] Fix | Delete
*
[2407] Fix | Delete
* @global PasswordHash $wp_hasher PHPass object used for checking the password
[2408] Fix | Delete
* against the $hash + $password
[2409] Fix | Delete
* @uses PasswordHash::CheckPassword
[2410] Fix | Delete
*
[2411] Fix | Delete
* @param string $password Plaintext user's password
[2412] Fix | Delete
* @param string $hash Hash of the user's password to check against.
[2413] Fix | Delete
* @param string|int $user_id Optional. User ID.
[2414] Fix | Delete
* @return bool False, if the $password does not match the hashed password
[2415] Fix | Delete
*/
[2416] Fix | Delete
function wp_check_password( $password, $hash, $user_id = '' ) {
[2417] Fix | Delete
global $wp_hasher;
[2418] Fix | Delete
[2419] Fix | Delete
// If the hash is still md5...
[2420] Fix | Delete
if ( strlen( $hash ) <= 32 ) {
[2421] Fix | Delete
$check = hash_equals( $hash, md5( $password ) );
[2422] Fix | Delete
if ( $check && $user_id ) {
[2423] Fix | Delete
// Rehash using new hash.
[2424] Fix | Delete
wp_set_password( $password, $user_id );
[2425] Fix | Delete
$hash = wp_hash_password( $password );
[2426] Fix | Delete
}
[2427] Fix | Delete
[2428] Fix | Delete
/**
[2429] Fix | Delete
* Filters whether the plaintext password matches the encrypted password.
[2430] Fix | Delete
*
[2431] Fix | Delete
* @since 2.5.0
[2432] Fix | Delete
*
[2433] Fix | Delete
* @param bool $check Whether the passwords match.
[2434] Fix | Delete
* @param string $password The plaintext password.
[2435] Fix | Delete
* @param string $hash The hashed password.
[2436] Fix | Delete
* @param string|int $user_id User ID. Can be empty.
[2437] Fix | Delete
*/
[2438] Fix | Delete
return apply_filters( 'check_password', $check, $password, $hash, $user_id );
[2439] Fix | Delete
}
[2440] Fix | Delete
[2441] Fix | Delete
// If the stored hash is longer than an MD5,
[2442] Fix | Delete
// presume the new style phpass portable hash.
[2443] Fix | Delete
if ( empty( $wp_hasher ) ) {
[2444] Fix | Delete
require_once ABSPATH . WPINC . '/class-phpass.php';
[2445] Fix | Delete
// By default, use the portable hash from phpass.
[2446] Fix | Delete
$wp_hasher = new PasswordHash( 8, true );
[2447] Fix | Delete
}
[2448] Fix | Delete
[2449] Fix | Delete
$check = $wp_hasher->CheckPassword( $password, $hash );
[2450] Fix | Delete
[2451] Fix | Delete
/** This filter is documented in wp-includes/pluggable.php */
[2452] Fix | Delete
return apply_filters( 'check_password', $check, $password, $hash, $user_id );
[2453] Fix | Delete
}
[2454] Fix | Delete
endif;
[2455] Fix | Delete
[2456] Fix | Delete
if ( ! function_exists( 'wp_generate_password' ) ) :
[2457] Fix | Delete
/**
[2458] Fix | Delete
* Generates a random password drawn from the defined set of characters.
[2459] Fix | Delete
*
[2460] Fix | Delete
* Uses wp_rand() is used to create passwords with far less predictability
[2461] Fix | Delete
* than similar native PHP functions like `rand()` or `mt_rand()`.
[2462] Fix | Delete
*
[2463] Fix | Delete
* @since 2.5.0
[2464] Fix | Delete
*
[2465] Fix | Delete
* @param int $length Optional. The length of password to generate. Default 12.
[2466] Fix | Delete
* @param bool $special_chars Optional. Whether to include standard special characters.
[2467] Fix | Delete
* Default true.
[2468] Fix | Delete
* @param bool $extra_special_chars Optional. Whether to include other special characters.
[2469] Fix | Delete
* Used when generating secret keys and salts. Default false.
[2470] Fix | Delete
* @return string The random password.
[2471] Fix | Delete
*/
[2472] Fix | Delete
function wp_generate_password( $length = 12, $special_chars = true, $extra_special_chars = false ) {
[2473] Fix | Delete
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
[2474] Fix | Delete
if ( $special_chars ) {
[2475] Fix | Delete
$chars .= '!@#$%^&*()';
[2476] Fix | Delete
}
[2477] Fix | Delete
if ( $extra_special_chars ) {
[2478] Fix | Delete
$chars .= '-_ []{}<>~`+=,.;:/?|';
[2479] Fix | Delete
}
[2480] Fix | Delete
[2481] Fix | Delete
$password = '';
[2482] Fix | Delete
for ( $i = 0; $i < $length; $i++ ) {
[2483] Fix | Delete
$password .= substr( $chars, wp_rand( 0, strlen( $chars ) - 1 ), 1 );
[2484] Fix | Delete
}
[2485] Fix | Delete
[2486] Fix | Delete
/**
[2487] Fix | Delete
* Filters the randomly-generated password.
[2488] Fix | Delete
*
[2489] Fix | Delete
* @since 3.0.0
[2490] Fix | Delete
* @since 5.3.0 Added the `$length`, `$special_chars`, and `$extra_special_chars` parameters.
[2491] Fix | Delete
*
[2492] Fix | Delete
* @param string $password The generated password.
[2493] Fix | Delete
* @param int $length The length of password to generate.
[2494] Fix | Delete
* @param bool $special_chars Whether to include standard special characters.
[2495] Fix | Delete
* @param bool $extra_special_chars Whether to include other special characters.
[2496] Fix | Delete
*/
[2497] Fix | Delete
return apply_filters( 'random_password', $password, $length, $special_chars, $extra_special_chars );
[2498] Fix | Delete
}
[2499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function