function user_password

Generate a random alphanumeric password.

8 calls to user_password()
DBLogTest::doUser in drupal/core/modules/dblog/lib/Drupal/dblog/Tests/DBLogTest.php
Generates and then verifies some user events.
openid_form_user_register_form_alter in drupal/core/modules/openid/openid.module
Implements hook_form_FORM_ID_alter().
RegisterFormController::submit in drupal/core/modules/user/lib/Drupal/user/RegisterFormController.php
Overrides Drupal\Core\Entity\EntityFormController::submit().
UpdateScriptTest::testUpdateAccess in drupal/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php
Tests access to the update script.
UserCancelTest::testUserCancelUid1 in drupal/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php
Tests that user account for uid 1 cannot be cancelled.

... See full list

File

drupal/core/modules/user/user.module, line 368
Enables the user registration and login system.

Code

function user_password($length = 10) {

  // This variable contains the list of allowable characters for the
  // password. Note that the number 0 and the letter 'O' have been
  // removed to avoid confusion between the two. The same is true
  // of 'I', 1, and 'l'.
  $allowable_characters = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';

  // Zero-based count of characters in the allowable list:
  $len = strlen($allowable_characters) - 1;

  // Declare the password as a blank string.
  $pass = '';

  // Loop the number of times specified by $length.
  for ($i = 0; $i < $length; $i++) {

    // Each iteration, pick a random character from the
    // allowable string and append it to the password:
    $pass .= $allowable_characters[mt_rand(0, $len)];
  }
  return $pass;
}