diff --git a/config/install/email_registration.settings.yml b/config/install/email_registration.settings.yml
new file mode 100644
index 0000000..f684df7
--- /dev/null
+++ b/config/install/email_registration.settings.yml
@@ -0,0 +1 @@
+login_with_username: FALSE
diff --git a/config/schema/email_registration.schema.yml b/config/schema/email_registration.schema.yml
new file mode 100644
index 0000000..a13fdd7
--- /dev/null
+++ b/config/schema/email_registration.schema.yml
@@ -0,0 +1,7 @@
+email_registration.settings:
+  type: config_object
+  label: 'Email registration config'
+  mapping:
+    login_with_username:
+      type: boolean
+      label: 'Allow users to log in with e-mail or username.'
diff --git a/email_registration.install b/email_registration.install
index a2245d9..3d41199 100644
--- a/email_registration.install
+++ b/email_registration.install
@@ -2,7 +2,7 @@
 
 /**
  * @file
- * Checks requirements for the email_registration.module.
+ * Update and installation requirement hooks for the Email Registration module.
  */
 
 /**
@@ -23,3 +23,13 @@ function email_registration_requirements() {
 
   return $requirements;
 }
+
+/**
+ * Add an option to log in with the username as well as the e-mail address.
+ */
+function email_registration_update_8100() {
+  $config_factory = \Drupal::configFactory();
+  $email_registration = $config_factory->getEditable('email_registration.settings');
+  $email_registration->set('login_with_username', FALSE);
+  $email_registration->save();
+}
diff --git a/email_registration.module b/email_registration.module
index 2a1e42a..a54a888 100644
--- a/email_registration.module
+++ b/email_registration.module
@@ -9,6 +9,7 @@ use Drupal\Component\Utility\Unicode;
 use Drupal\user\UserInterface;
 use Drupal\Core\Render\Element\Email;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Url;
 
 /**
  * Implements hook_ENTITY_TYPE_insert().
@@ -44,12 +45,7 @@ function email_registration_user_insert(UserInterface $account) {
   // Ensure whatever name we have is unique.
   $new_name = email_registration_unique_username($new_name, $account->id());
 
-  $account->setUsername($new_name);
-  if ($account->isValidationRequired() && !$account->validate()) {
-    \Drupal::logger('email_registration')->error('Email registration failed setting the new name on user @id.', ['@id' => $account->id()]);
-    return;
-  }
-  $account->save();
+  $account->setUsername($new_name)->save();
 }
 
 /**
@@ -138,12 +134,14 @@ function email_registration_form_user_pass_alter(&$form, FormStateInterface $for
  * Implements hook_form_FORM_ID_alter().
  */
 function email_registration_form_user_login_form_alter(&$form, FormStateInterface $form_state) {
-  $form['name']['#title'] = t('E-mail');
-  $form['name']['#description'] = t('Enter your e-mail address.');
+  $config = \Drupal::config('email_registration.settings');
+  $login_with_username = $config->get('login_with_username');
+  $form['name']['#title'] = isset($login_with_username) ? t('E-mail or username') : t('E-mail');
+  $form['name']['#description'] = isset($login_with_username) ? t('Enter your e-mail address or username.') : t('Enter your e-mail address.');
   $form['name']['#element_validate'][] = 'email_registration_user_login_validate';
   $form['pass']['#description'] = t('Enter the password that accompanies your e-mail.');
   // Allow client side validation of input format.
-  $form['name']['#type'] = 'email';
+  $form['name']['#type'] = !isset($login_with_username) ? 'email' : 'textfield';
   $form['name']['#maxlength'] = Email::EMAIL_MAX_LENGTH;
 }
 
@@ -154,9 +152,16 @@ function email_registration_form_user_login_form_alter(&$form, FormStateInterfac
  */
 function email_registration_user_login_validate($form, FormStateInterface $form_state) {
   $mail = $form_state->getValue('name');
-  if (!empty($mail) && ($user = user_load_by_mail($mail))) {
-    // Keep the email value in form state for further validation.
-    $form_state->setValue('name', $user->getAccountName());
+  if (!empty($mail)) {
+    $config = \Drupal::config('email_registration.settings');
+    if ($user = user_load_by_mail($mail)) {
+      $form_state->setValue('name', $user->getAccountName());
+    }
+    elseif (!$config->get('login_with_username')) {
+      $user_input = $form_state->getUserInput();
+      $query = isset($user_input['name']) ? ['name' => $user_input['name']] : [];
+      $form_state->setErrorByName('name', t('Unrecognized e-mail address or password. <a href=":password">Forgot your password?</a>', [':password' => Url::fromRoute('user.pass', [], ['query' => $query])->toString()]));
+    }
   }
 }
 
@@ -166,3 +171,27 @@ function email_registration_user_login_validate($form, FormStateInterface $form_
 function email_registration_form_user_form_alter(&$form, FormStateInterface $form_state) {
   $form['account']['name']['#title'] = t('Display name');
 }
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ */
+function email_registration_form_user_admin_settings_alter(&$form, FormStateInterface $form_state) {
+  $config = \Drupal::config('email_registration.settings');
+  $form['registration_cancellation']['login_with_username'] = [
+    '#type' => 'checkbox',
+    '#title' => t('Allow to log in with e-mail or username.'),
+    '#description' => t('Allow users to log in with either their username or their e-mail address.'),
+    '#default_value' => $config->get('login_with_username'),
+  ];
+  $form['#submit'][] = 'email_registration_form_user_admin_settings_submit';
+}
+
+/**
+ * Submit function for user_admin_settings to save our variable.
+ *
+ * @see email_registration_form_user_admin_settings_alter().
+ */
+function email_registration_form_user_admin_settings_submit(array &$form, FormStateInterface $form_state) {
+  $config = \Drupal::configFactory()->getEditable('email_registration.settings');
+  $config->set('login_with_username', $form_state->getValue('login_with_username'))->save();
+}
diff --git a/src/Tests/EmailRegistrationTestCase.php b/src/Tests/EmailRegistrationTestCase.php
index 776ea76..6e755cd 100644
--- a/src/Tests/EmailRegistrationTestCase.php
+++ b/src/Tests/EmailRegistrationTestCase.php
@@ -23,6 +23,7 @@ class EmailRegistrationTestCase extends WebTestBase {
    */
   public function testRegistration() {
     $user_config = $this->container->get('config.factory')->getEditable('user.settings');
+    $email_registration_config = $this->container->get('config.factory')->getEditable('email_registration.settings');
     $user_config
       ->set('verify_mail', FALSE)
       ->set('register', USER_REGISTER_VISITORS)
@@ -49,6 +50,21 @@ class EmailRegistrationTestCase extends WebTestBase {
 
     // Now try the immediate login.
     $this->drupalLogout();
+
+    // Try to login with just username, should fail by default.
+    $login = array(
+      'name' => $name,
+      'pass' => $pass,
+    );
+    $this->drupalPostForm('user/login', $login, t('Log in'));
+    $this->assertFieldByXpath('//div[contains(@class, "error")]', NULL, t('When login_with_username is false, a user cannot login with just their username.'));
+
+    // Set login_with_username to TRUE and try to login with just username.
+    $email_registration_config->set('login_with_username', TRUE)->save();
+    $this->drupalPostForm('user/login', $login, t('Log in'));
+    $this->assertRaw('<title>' . $name . ' | Drupal</title>', t('When login_with_username is true, a user can login with just their username.'));
+    $this->drupalLogout();
+
     $user_config
       ->set('verify_mail', FALSE)
       ->save();
