You are here

function user_password in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/user.module \user_password()
  2. 4 modules/user.module \user_password()
  3. 5 modules/user/user.module \user_password()
  4. 6 modules/user/user.module \user_password()
  5. 7 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 231
Enables the user registration and login system.

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);
}