• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / wp_generate_password() – Generates a random password drawn from the defined set of characters.

You appear to be a bot. Output may be restricted

Description

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

Uses wp_rand() is used to create passwords with far less predictability than similar native PHP functions like rand() or `mt_rand()`.

Usage

$string = wp_generate_password( $length, $special_chars, $extra_special_chars );

Parameters

$length
( int ) optional default: 12 – Optional. The length of password to generate. Default 12.
$special_chars
( bool ) optional default: 1 – Optional. Whether to include standard special characters. Default true.
$extra_special_chars
( bool ) optional – Optional. Whether to include other special characters. Used when generating secret keys and salts. Default false.

Returns

string The random password.

Source

File name: wordpress/wp-includes/pluggable.php
Lines:

1 to 27 of 27
  function wp_generate_password( $length = 12, $special_chars = true, $extra_special_chars = false ) {
    $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    if ( $special_chars ) {
      $chars .= '!@#$%^&*()';
    }
    if ( $extra_special_chars ) {
      $chars .= '-_ []{}<>~`+=,.;:/?|';
    }

    $password = '';
    for ( $i = 0; $i < $length; $i++ ) {
      $password .= substr( $chars, wp_rand( 0, strlen( $chars ) - 1 ), 1 );
    }

    
/**
 * Filters the randomly-generated password.
 *
 * @since 3.0.0
 * @since 5.3.0 Added the `$length`, `$special_chars`, and `$extra_special_chars` parameters.
 *
 * @param string $password            The generated password.
 * @param int    $length              The length of password to generate.
 * @param bool   $special_chars       Whether to include standard special characters.
 * @param bool   $extra_special_chars Whether to include other special characters.
 */
    return apply_filters( 'random_password', $password, $length, $special_chars, $extra_special_chars );
  }
 

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 25th November 2019

Primary Sidebar

Information

Function name: wp_generate_password
Plugin ref: WordPress
Version: 5.6
Sourcefile: wp-includes/pluggable.php
File ref: wp-includes/pluggable.php
Deprecated?: No
API Letters: G,P,W

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites