Same name and namespace in other branches
- 4.7.x modules/user.module \user_password()
- 5.x modules/user/user.module \user_password()
- 6.x modules/user/user.module \user_password()
- 7.x modules/user/user.module \user_password()
- 8.9.x core/modules/user/user.module \user_password()
- 9 core/modules/user/user.module \user_password()
Generate a random alphanumeric password.
3 calls to user_password()
- system_view_general in modules/
system.module - user_pass in modules/
user.module - user_register in modules/
user.module
File
- modules/
user.module, line 283 - 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' and 1.
$allowable_characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
// We see how many characters are in the allowable list:
$len = strlen($allowable_characters);
// Seed the random number generator with the microtime stamp.
mt_srand((double) microtime() * 1000000);
// 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 - 1)];
}
return $pass;
}