function user_password in Drupal 8
Same name and namespace in other branches
- 4 modules/user.module \user_password()
- 5 modules/user/user.module \user_password()
- 6 modules/user/user.module \user_password()
- 7 modules/user/user.module \user_password()
- 9 core/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.
8 calls to user_password()
- DbLogTest::doUser in core/
modules/ dblog/ tests/ src/ Functional/ DbLogTest.php - Generates and then verifies some user events.
- EntityReferenceSelectionAccessTest::testUserHandler in core/
modules/ system/ tests/ src/ Functional/ Entity/ EntityReferenceSelection/ EntityReferenceSelectionAccessTest.php - Test the user-specific overrides of the entity handler.
- RegisterForm::submitForm in core/
modules/ user/ src/ RegisterForm.php - This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state…
- UserCreationTrait::createUser in core/
modules/ user/ tests/ src/ Traits/ UserCreationTrait.php - Create a user with a given set of permissions.
- UserPasswordResetTest::testUserPasswordReset in core/
modules/ user/ tests/ src/ Functional/ UserPasswordResetTest.php - Tests password reset functionality.
File
- core/
modules/ user/ user.module, line 321 - Enables the user registration and login system.
Code
function user_password($length = 10) {
// This variable contains the list of allowed 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'.
$allowed_characters = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
// The maximum integer we want from random_int().
$max = strlen($allowed_characters) - 1;
$pass = '';
for ($i = 0; $i < $length; $i++) {
$pass .= $allowed_characters[random_int(0, $max)];
}
return $pass;
}