function user_password in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/user/user.module \user_password()
Generate a random alphanumeric password.
9 calls to user_password()
- BrowserTestBase::drupalCreateUser in core/
modules/ simpletest/ src/ BrowserTestBase.php - Creates a user with a given set of permissions.
- DbLogTest::doUser in core/
modules/ dblog/ src/ Tests/ DbLogTest.php - Generates and then verifies some user events.
- EntityReferenceSelectionAccessTest::testUserHandler in core/
modules/ system/ src/ Tests/ 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…
- UserCancelTest::testUserCancelUid1 in core/
modules/ user/ src/ Tests/ UserCancelTest.php - Tests that user account for uid 1 cannot be cancelled.
File
- core/
modules/ user/ user.module, line 279 - 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(Crypt::randomBytes(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;
}