WordPress.org

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp generate password

Description

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

Parameters

$length
(integer) (Optional) The length of the password to generate.
Default: 12
$special_chars
(boolean) (Optional) Whether to include standard special characters.
Default: true
$extra_special_chars
(boolean) (Optional) Whether to include other special characters. Used when generating secret keys and salts.
Default: false

Return values

(string) 
The random password.

Usage

<?php wp_generate_password(); ?>

Examples

Generate a 12 character password using these characters: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()

<?php echo 'New password: ' . wp_generate_password(); ?>

Generate an 8 character password using only letters and numbers:

<?php echo 'New password: ' . wp_generate_password( 8, false ); ?>

Generate an 10 character password consisting of letters, numbers, special characters (!@#$%^&*()), and extra special characters (-_ []{}<>~`+=,.;:/?|):

<?php echo 'New password: ' . wp_generate_password( 10, true, true ); ?>

Notes

  • This function executes the random_password filter after generating the password.
  • Normal characters: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
  • Special characters: !@#$%^&*()
  • Extra special characters: -_ []{}<>~`+=,.;:/?|'

Change Log

Since: 2.5

Source File

wp_generate_password() is located in wp-includes/pluggable.php.

Related