/**
  * Checks if user name does not break logics:
  *  - if user wants to UPDATE his login name, performing check if
  *    user entered correct password
  *  - additionally checking for user name dublicates. This is usually
  *    needed when creating new users.
  * On any error exception is thrown.
  *
  * @param oxuser $oUser       active user
  * @param string $sLogin      user preferred login name
  * @param array  $aInvAddress user information
  *
  * @return string login name
  */
 public function checkLogin($oUser, $sLogin, $aInvAddress)
 {
     // check only for users with password during registration
     // if user wants to change user name - we must check if passwords are ok before changing
     if ($oUser->oxuser__oxpassword->value && $sLogin != $oUser->oxuser__oxusername->value) {
         // on this case password must be taken directly from request
         $sNewPass = isset($aInvAddress['oxuser__oxpassword']) && $aInvAddress['oxuser__oxpassword'] ? $aInvAddress['oxuser__oxpassword'] : oxConfig::getParameter('user_password');
         if (!$sNewPass) {
             // 1. user forgot to enter password
             $oEx = oxNew('oxInputException');
             $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
             return $this->_addValidationError("oxuser__oxpassword", $oEx);
         } else {
             // 2. entered wrong password
             if (!$oUser->isSamePassword($sNewPass)) {
                 $oEx = oxNew('oxUserException');
                 $oEx->setMessage('EXCEPTION_USER_PWDDONTMATCH');
                 return $this->_addValidationError("oxuser__oxpassword", $oEx);
             }
         }
     }
     if ($oUser->checkIfEmailExists($sLogin)) {
         //if exists then we do now allow to do that
         $oEx = oxNew('oxUserException');
         $oLang = oxLang::getInstance();
         $oEx->setMessage(sprintf($oLang->translateString('EXCEPTION_USER_USEREXISTS', $oLang->getTplLanguage()), $sLogin));
         return $this->_addValidationError("oxuser__oxusername", $oEx);
     }
 }