Title: random_password
Published: April 25, 2014
Last modified: February 24, 2026

---

# apply_filters( ‘random_password’, string $password, int $length, bool $special_chars, bool $extra_special_chars )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/random_password/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/random_password/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/random_password/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/random_password/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/random_password/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/random_password/?output_format=md#wp--skip-link--target)

Filters the randomly-generated password.

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

 `$password`string

The generated password.

`$length`int

The length of password to generate.

`$special_chars`bool

Whether to include standard special characters.

`$extra_special_chars`bool

Whether to include other special characters.

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

    ```php
    return apply_filters( 'random_password', $password, $length, $special_chars, $extra_special_chars );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/pluggable.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/pluggable.php#L2985)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/pluggable.php#L2985-L2985)

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

| Used by | 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.

  |

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

| Version | Description | 
| [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | Added the `$length`, `$special_chars`, and `$extra_special_chars` parameters. | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/random_password/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/random_password/?output_format=md#comment-content-4639)
 2.   [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/random_password/#comment-4639)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frandom_password%2F%23comment-4639)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frandom_password%2F%23comment-4639)
 4. Example migrated from Codex:
 5. Form a new password by appending your own password string to the generated password.
 6.     ```php
        add_filter( 'random_password', 'my_random_password' );
    
        function my_random_password() {
            $characters ='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
            $length = 10;
            $password = '';
            for( $i = 0; $i < $length; $i++ ) {
                $password .= substr( $characters , wp_rand( 0, strlen( $characters ) - 1 ), 1 );
            }
            return $password;
        }
        ```
    
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frandom_password%2F%3Freplytocom%3D4639%23feedback-editor-4639)

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