function user_password

Same name in other branches
  1. 7.x modules/user/user.module \user_password()
  2. 8.9.x core/modules/user/user.module \user_password()

Generate a random alphanumeric password.

Parameters

int $length: The desired password length, in characters.

Return value

string The generated random password.

Deprecated

in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Password\PasswordGeneratorInterface::generate() instead.

See also

https://www.drupal.org/node/3153113

1 call to user_password()
UserLegacyTest::testUserPassword in core/modules/user/tests/src/Kernel/UserLegacyTest.php

File

core/modules/user/user.module, line 235

Code

function user_password($length = 10) {
    @trigger_error('user_password() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \\Drupal\\Core\\Password\\PasswordGeneratorInterface::generate() instead. See https://www.drupal.org/node/3153113', E_USER_DEPRECATED);
    return \Drupal::service('password_generator')->generate($length);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.