生成从定义的字符集中提取的随机密码。
原型
wp_generate_password( int $length = 12, bool $special_chars = true, bool $extra_special_chars = false )
参数
$length
(int)
(Optional)
要生成的密码长度。
$special_chars
(bool)
(Optional)
是否包含标准特殊字符。
$extra_special_chars
(bool)
(Optional)
是否包含其他特殊字符。在生成密钥和盐时使用。
返回值
(string)
随机密码。
源文件
路径:wp-includes/pluggable.php
<?php
...
function wp_generate_password( $length = 12, $special_chars = true, $extra_special_chars = false ) {
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
if ( $special_chars )
$chars .= '[email protected]#$%^&*()';
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
*
* @param string $password The generated password.
*/
return apply_filters( 'random_password', $password );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_generate_password/