Title: WP_Recovery_Mode_Cookie_Service::recovery_mode_hash
Published: May 7, 2019
Last modified: August 20, 2026

---

# WP_Recovery_Mode_Cookie_Service::recovery_mode_hash( string $data ): string|false

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/recovery_mode_hash/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/recovery_mode_hash/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/recovery_mode_hash/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/recovery_mode_hash/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/recovery_mode_hash/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/recovery_mode_hash/?output_format=md#changelog)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Gets a form of `wp_hash()` specific to Recovery Mode.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/recovery_mode_hash/?output_format=md#description)󠁿

We cannot use `wp_hash()` because it is defined in `pluggable.php` which is not 
loaded until after plugins are loaded, which is too late to verify the recovery 
mode cookie.

This tries to use the `AUTH` salts first, but if they aren’t valid specific salts
will be generated and stored.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/recovery_mode_hash/?output_format=md#parameters)󠁿

 `$data`stringrequired

Data to hash.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/recovery_mode_hash/?output_format=md#return)󠁿

 string|false The hashed $data, or false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/recovery_mode_hash/?output_format=md#source)󠁿

    ```php
    private function recovery_mode_hash( $data ) {
    	$default_keys = array_unique(
    		array(
    			'put your unique phrase here',
    			/*
    			 * translators: This string should only be translated if wp-config-sample.php is localized.
    			 * You can check the localized release package or
    			 * https://i18n.svn.wordpress.org/<locale code>/branches/<wp version>/dist/wp-config-sample.php
    			 */
    			__( 'put your unique phrase here' ),
    		)
    	);

    	if ( ! defined( 'AUTH_KEY' ) || in_array( AUTH_KEY, $default_keys, true ) ) {
    		$auth_key = get_site_option( 'recovery_mode_auth_key' );

    		if ( ! $auth_key ) {
    			if ( ! function_exists( 'wp_generate_password' ) ) {
    				require_once ABSPATH . WPINC . '/pluggable.php';
    			}

    			$auth_key = wp_generate_password( 64, true, true );
    			update_site_option( 'recovery_mode_auth_key', $auth_key );
    		}
    	} else {
    		$auth_key = AUTH_KEY;
    	}

    	if ( ! defined( 'AUTH_SALT' ) || in_array( AUTH_SALT, $default_keys, true ) || AUTH_SALT === $auth_key ) {
    		$auth_salt = get_site_option( 'recovery_mode_auth_salt' );

    		if ( ! $auth_salt ) {
    			if ( ! function_exists( 'wp_generate_password' ) ) {
    				require_once ABSPATH . WPINC . '/pluggable.php';
    			}

    			$auth_salt = wp_generate_password( 64, true, true );
    			update_site_option( 'recovery_mode_auth_salt', $auth_salt );
    		}
    	} else {
    		$auth_salt = AUTH_SALT;
    	}

    	$secret = $auth_key . $auth_salt;

    	return hash_hmac( 'sha1', $data, $secret );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-recovery-mode-cookie-service.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/class-wp-recovery-mode-cookie-service.php#L200)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/class-wp-recovery-mode-cookie-service.php#L200-L246)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/recovery_mode_hash/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_generate_password()](https://developer.wordpress.org/reference/functions/wp_generate_password/)`wp-includes/pluggable.php` |

Generates a random password drawn from the defined set of characters.

  | 
| [update_site_option()](https://developer.wordpress.org/reference/functions/update_site_option/)`wp-includes/option.php` |

Updates the value of an option that was already added for the current network.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [get_site_option()](https://developer.wordpress.org/reference/functions/get_site_option/)`wp-includes/option.php` |

Retrieve an option value for the current network based on name of option.

  |

[Show 2 more](https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/recovery_mode_hash/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/recovery_mode_hash/?output_format=md#)

| Used by | Description | 
| [WP_Recovery_Mode_Cookie_Service::validate_cookie()](https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/validate_cookie/)`wp-includes/class-wp-recovery-mode-cookie-service.php` |

Validates the recovery mode cookie.

  | 
| [WP_Recovery_Mode_Cookie_Service::generate_cookie()](https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/generate_cookie/)`wp-includes/class-wp-recovery-mode-cookie-service.php` |

Generates the recovery mode cookie value.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/recovery_mode_hash/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.2.0](https://developer.wordpress.org/reference/since/5.2.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_recovery_mode_cookie_service%2Frecovery_mode_hash%2F)
before being able to contribute a note or feedback.