wp_generate_password()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
wp_generate_password( int $length = 12, bool $special_chars = true, bool $extra_special_chars = false ): string
Описание
Использует wp_rand() для создания паролей с гораздо меньшей предсказуемостью, чем у аналогичных встроенных функций PHP, таких как rand() или mt_rand().
Оригинал (английский)
Uses wp_rand() to create passwords with far less predictability than similar native PHP functions like rand() or mt_rand().
Параметры
$length
int
необязательный
= 12
$special_chars
bool
необязательный
= true
$extra_special_chars
bool
необязательный
= false
Возвращаемое значение
string
Исходный код
wp-includes/pluggable.php:2960
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 );
}
История изменений
| Версия | Описание |
|---|---|
| 2.5.0 | Introduced. |

