check_password_reset_key( string $key, string $login ): WP_User|WP_Error
- Since
- 3.1.0
- Source
wp-includes/user.php:3176
Description
A key is considered 'expired' if it exactly matches the value of the user_activation_key field, rather than being matched after going through the hashing process. This field is now hashed; old values are no longer accepted but have a different WP_Error code so good user feedback can be provided.
Compatibility
- WordPress
- since 3.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$keystring- The password reset key.
$loginstring- The user login.
Return value
WP_User|WP_Error- WP_User object on success, WP_Error object for invalid or expired keys.
Performance profile
How much work a call to check_password_reset_key() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 15–76
- Plugin surface
- 2 hooks
- Called by
- 0
Reaches the database via get_user_by().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 127.
Third-party callbacks on 'password_reset_expiration', 'password_reset_key_expired' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- querycontent query
get_user_by()called directly - hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 18 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost check_password_reset_key() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 15–21 | __() |
!empty($key) && is_string($key) && !empty($login) && is_string($login) | 27 | get_user_by(), __() |
!empty($key) && is_string($key) && !empty($login) && is_string($login) && !$user | 39 | get_user_by(), apply_filters(), __() |
!empty($key) && is_string($key) && !empty($login) && is_string($login) && $user && $expiration_time | 43 | get_user_by(), apply_filters(), wp_verify_fast_hash(), time() |
!empty($key) && is_string($key) && !empty($login) && is_string($login) && $user | 48 | get_user_by(), apply_filters(), wp_verify_fast_hash(), __() |
!empty($key) && is_string($key) && !empty($login) && is_string($login) && !$user | 48 | get_user_by(), apply_filters(), explode(), __() |
!empty($key) && is_string($key) && !empty($login) && is_string($login) && $user && !hash_equals() | 52–56 | get_user_by(), apply_filters(), wp_verify_fast_hash(), hash_equals(), __() |
!empty($key) && is_string($key) && !empty($login) && is_string($login) && $user && !$expiration_time | 52 | get_user_by(), apply_filters(), wp_verify_fast_hash(), time(), __() |
!empty($key) && is_string($key) && !empty($login) && is_string($login) && $user && $expiration_time | 52 | get_user_by(), apply_filters(), explode(), wp_verify_fast_hash(), time() |
!empty($key) && is_string($key) && !empty($login) && is_string($login) && $user | 57 | get_user_by(), apply_filters(), explode(), wp_verify_fast_hash(), __() |
!empty($key) && is_string($key) && !empty($login) && is_string($login) && $user | 58–63 | get_user_by(), apply_filters(), wp_verify_fast_hash(), hash_equals(), __(), apply_filters() |
!empty($key) && is_string($key) && !empty($login) && is_string($login) && $user && !$expiration_time && !hash_equals() | 58–60 | get_user_by(), apply_filters(), wp_verify_fast_hash(), time(), hash_equals(), __() |
6 further outcomes, up to 76 instructions
!empty($key) && is_string($key) && !empty($login) && is_string($login) && $user && !hash_equals() | 61–65 | get_user_by(), apply_filters(), explode(), wp_verify_fast_hash(), hash_equals(), __() |
!empty($key) && is_string($key) && !empty($login) && is_string($login) && $user && !$expiration_time | 61 | get_user_by(), apply_filters(), explode(), wp_verify_fast_hash(), time(), __() |
!empty($key) && is_string($key) && !empty($login) && is_string($login) && $user && !$expiration_time | 64–67 | get_user_by(), apply_filters(), wp_verify_fast_hash(), time(), hash_equals(), __(), apply_filters() |
!empty($key) && is_string($key) && !empty($login) && is_string($login) && $user | 67–72 | get_user_by(), apply_filters(), explode(), wp_verify_fast_hash(), hash_equals(), __(), apply_filters() |
!empty($key) && is_string($key) && !empty($login) && is_string($login) && $user && !$expiration_time && !hash_equals() | 67–69 | get_user_by(), apply_filters(), explode(), wp_verify_fast_hash(), time(), hash_equals(), __() |
!empty($key) && is_string($key) && !empty($login) && is_string($login) && $user && !$expiration_time | 73–76 | get_user_by(), apply_filters(), explode(), wp_verify_fast_hash(), time(), hash_equals(), __(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 127 | 15–76 | 15 | |
| 8.5 | 127 | 15–76 | 15 | |
| 8.4 | 127 | 15–76 | 15 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 133 | 18–82 | 15 | |
| 8.2 | 133 | 18–82 | 15 | |
| 8.1 | 133 | 18–82 | 15 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 134 | 18–83 | 15 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 2
2 hooks fire while check_password_reset_key() runs, in this order:
- apply_filters( password_reset_expiration )filterline 3204 (+28 into the body)
Filters the expiration time of password reset keys.
- apply_filters( password_reset_key_expired )filterline 3244 (+68 into the body)
Filters the return value of check_password_reset_key() when an old-style key or an expired key is used.
Uses · 6
- __()Retrieves the translation of $text.
- get_user_by()Retrieves user info by a given field.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- wp_verify_fast_hash()Checks whether a plaintext message matches the hashed value. Used to verify values hashed via wp_fast_hash().
- WP_Error::__construct()Initializes the error.
Changelog
Introduced in 3.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/user.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.