function user_password

Generate a random alphanumeric password.

12 calls to user_password()
DBLogTestCase::doUser in drupal/modules/dblog/dblog.test
Generates and then verifies some user events.
DrupalWebTestCase::drupalCreateUser in drupal/modules/simpletest/drupal_web_test_case.php
Create a user with a given set of permissions.
openid_form_user_register_form_alter in drupal/modules/openid/openid.module
Implements hook_form_FORM_ID_alter().
TriggerOtherTestCase::testActionsUser in drupal/modules/trigger/trigger.test
Tests triggering on user create and user login.
UpdateScriptFunctionalTest::testUpdateAccess in drupal/modules/system/system.test
Tests access to the update script.

... See full list

File

drupal/modules/user/user.module, line 708
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++) {
    do {

      // Find a secure random number within the range needed.
      $index = ord(drupal_random_bytes(1));
    } while ($index > $len);

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