You are here

function user_password in Drupal 5

Same name and namespace in other branches
  1. 8 core/modules/user/user.module \user_password()
  2. 4 modules/user.module \user_password()
  3. 6 modules/user/user.module \user_password()
  4. 7 modules/user/user.module \user_password()
  5. 9 core/modules/user/user.module \user_password()

Generate a random alphanumeric password.

2 calls to user_password()
user_authenticate in modules/user/user.module
user_register_submit in modules/user/user.module

File

modules/user/user.module, line 322
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;
}