WordPress.org

Ready to get started?Download WordPress

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

$len
(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();
?>

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