diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index 2aeaaa9..a1a1404 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -621,7 +621,7 @@ protected function checkPermissions(array $permissions, $reset = FALSE) {
*
* @param $account
* User object representing the user to log in.
- * @param $by_email
+ * @param bool $by_email
* Whether to use email for login instead of username.
*
* @see drupalCreateUser()
diff --git a/core/modules/user/lib/Drupal/user/Tests/UserLoginTest.php b/core/modules/user/lib/Drupal/user/Tests/UserLoginTest.php
index 7e88b73..5831a30 100644
--- a/core/modules/user/lib/Drupal/user/Tests/UserLoginTest.php
+++ b/core/modules/user/lib/Drupal/user/Tests/UserLoginTest.php
@@ -24,29 +24,34 @@ public static function getInfo() {
/**
- * Test that login credentials work.
+ * Test that login credentials work with each method.
*/
function testLoginByEmail() {
$account = $this->drupalCreateUser(array());
- // Login via name.
+ // Login test with username only, the default method.
+ // Using e-mail should fail with username only method.
$this->drupalLogin($account);
+ // Using username should pass.
$this->assertFailedLogin($account, NULL, TRUE);
- // Login via email only.
+ // Login test with e-mail only method.
config('user.settings')
->set('user_login_method', USER_LOGIN_EMAIL_ONLY)
->save();
+ // Using e-mail shoud pass.
$this->drupalLogin($account, TRUE);
+ // Using username should fail.
$this->assertFailedLogin($account);
- // Login via name or email.
+ // Login test with username or e-mail method.
config('user.settings')
->set('user_login_method', USER_LOGIN_USERNAME_OR_EMAIL)
->save();;
+ // Using e-mail should pass.
$this->drupalLogin($account, TRUE);
+ // Using username should pass.
$this->drupalLogin($account);
-
}
/**
@@ -166,7 +171,7 @@ function testPasswordRehashOnLogin() {
* @param $flood_trigger
* Whether or not to expect that the flood control mechanism will be
* triggered.
- * @param $by_email
+ * @param bool $by_email
* Authenticate with email instead of username.
*/
function assertFailedLogin($account, $flood_trigger = NULL, $by_email = FALSE) {
@@ -193,6 +198,7 @@ function assertFailedLogin($account, $flood_trigger = NULL, $by_email = FALSE) {
case USER_LOGIN_USERNAME_ONLY:
$this->assertText(t('Sorry, unrecognized username or password. Have you forgotten your password?'));
break;
+
case USER_LOGIN_EMAIL_ONLY:
if (!$by_email) {
$this->assertText(t('The e-mail address @email is not valid.', array('@email' => $account->name)));
@@ -201,6 +207,7 @@ function assertFailedLogin($account, $flood_trigger = NULL, $by_email = FALSE) {
$this->assertText(t('Sorry, unrecognized e-mail address or password. Have you forgotten your password?'));
}
break;
+
case USER_LOGIN_USERNAME_OR_EMAIL:
$this->assertText(t('Sorry, unrecognized username, e-mail address or password. Have you forgotten your password?'));
break;
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index caf114d..d0c5800 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -1329,8 +1329,12 @@ function user_login_default_validators() {
}
/**
- * A FAPI validate handler. Depending on user_login_method, delegates
- * validation to user_login_username_validate() and valid_email_address().
+ * A FAPI validate handler.
+ *
+ * Depending on user_login_method, delegates to valid_email_address(). Sets an
+ * error if username is blocked.
+ *
+ * @see user_login_default_validators()
*/
function user_login_name_validate($form, &$form_state) {
if (isset($form_state['values']['name'])) {
@@ -1437,12 +1441,14 @@ function user_login_final_validate($form, &$form_state) {
case USER_LOGIN_USERNAME_ONLY:
form_set_error('name', t('Sorry, unrecognized username or password. Have you forgotten your password?', array('@password' => url('user/password'))));
break;
+
case USER_LOGIN_EMAIL_ONLY:
form_set_error('name', t('Sorry, unrecognized e-mail address or password. Have you forgotten your password?', array('@password' => url('user/password'))));
break;
+
case USER_LOGIN_USERNAME_OR_EMAIL:
form_set_error('name', t('Sorry, unrecognized username, e-mail address or password. Have you forgotten your password?', array('@password' => url('user/password'))));
- break;
+ break;
}
watchdog('user', 'Login attempt failed for %user.', array('%user' => $form_state['values']['name']));
}