/**
  * {@inheritdoc}
  */
 public function authenticate($username, $password)
 {
     try {
         switch ($this->advancedLoginConfigProvider->getLoginMode()) {
             case LoginMode::LOGIN_TYPE_ONLY_ATTRIBUTE:
                 $customer = $this->loginViaCustomerAttributeOnly($username);
                 break;
             case LoginMode::LOGIN_TYPE_BOTH:
                 $customer = $this->loginViaCustomerAttributeOrEmail($username);
                 break;
             default:
                 $customer = $this->loginViaEmailOnly($username);
                 break;
         }
     } catch (NoSuchEntityException $e) {
         throw new InvalidEmailOrPasswordException(__('Invalid login or password.'));
     }
     $this->checkPasswordStrength($password);
     $hash = $this->customerRegistry->retrieveSecureData($customer->getId())->getPasswordHash();
     if (!$this->encryptor->validateHash($password, $hash)) {
         throw new InvalidEmailOrPasswordException(__('Invalid login or password.'));
     }
     if ($customer->getConfirmation() && $this->isConfirmationRequired($customer)) {
         throw new EmailNotConfirmedException(__('This account is not confirmed.'));
     }
     $customerModel = $this->customerFactory->create()->updateData($customer);
     $this->eventManager->dispatch('customer_customer_authenticated', ['model' => $customerModel, 'password' => $password]);
     $this->eventManager->dispatch('customer_data_object_login', ['customer' => $customer]);
     return $customer;
 }
 /**
  * Retrieve the email field config
  *
  * @return array
  */
 public function getEmailFieldConfig()
 {
     switch ($this->advancedLoginConfigProvider->getLoginMode()) {
         case LoginMode::LOGIN_TYPE_ONLY_ATTRIBUTE:
             $label = $this->advancedLoginConfigProvider->getLoginAttributeLabel();
             $type = 'text';
             $dataValidate = "{required:true}";
             break;
         case LoginMode::LOGIN_TYPE_BOTH:
             $label = 'Email / ' . $this->advancedLoginConfigProvider->getLoginAttributeLabel();
             $type = 'text';
             $dataValidate = "{required:true}";
             break;
         default:
             $label = 'Email';
             $type = 'email';
             $dataValidate = "{required:true, 'validate-email':true}";
             break;
     }
     return ['label' => $label, 'type' => $type, 'data_validate' => $dataValidate];
 }