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

Filters the randomly-generated password.

Parameters

$passwordstring
The generated password.
$lengthint
The length of password to generate.
$special_charsbool
Whether to include standard special characters.
$extra_special_charsbool
Whether to include other special characters.

Source

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

Changelog

VersionDescription
5.3.0Added the $length, $special_chars, and $extra_special_chars parameters.
3.0.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Example migrated from Codex:

    Form a new password by appending your own password string to the generated password.

    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;
    }

You must log in before being able to contribute a note or feedback.