/**
  * @param \RainLoop\Account $oAccount
  * @param array $aSmtpCredentials
  */
 public function FilterSmtpCredentials($oAccount, &$aSmtpCredentials)
 {
     if ($oAccount instanceof \RainLoop\Account && \is_array($aSmtpCredentials)) {
         $sEmail = $oAccount->Email();
         $sHost = \trim($this->Config()->Get('plugin', 'smtp_host', ''));
         $sWhiteList = \trim($this->Config()->Get('plugin', 'override_users', ''));
         if (0 < strlen($sWhiteList) && 0 < \strlen($sHost) && \RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sWhiteList)) {
             $aSmtpCredentials['Host'] = $sHost;
             $aSmtpCredentials['Port'] = (int) $this->Config()->Get('plugin', 'smtp_port', 25);
             $sSecure = \trim($this->Config()->Get('plugin', 'smtp_secure', 'None'));
             switch ($sSecure) {
                 case 'SSL':
                     $aSmtpCredentials['Secure'] = MailSo\Net\Enumerations\ConnectionSecurityType::SSL;
                     break;
                 case 'TLS':
                     $aSmtpCredentials['Secure'] = MailSo\Net\Enumerations\ConnectionSecurityType::STARTTLS;
                     break;
                 default:
                     $aSmtpCredentials['Secure'] = MailSo\Net\Enumerations\ConnectionSecurityType::NONE;
                     break;
             }
             $aSmtpCredentials['UseAuth'] = (bool) $this->Config()->Get('plugin', 'smtp_auth', true);
             $aSmtpCredentials['Login'] = \trim($this->Config()->Get('plugin', 'smtp_user', ''));
             $aSmtpCredentials['Password'] = (string) $this->Config()->Get('plugin', 'smtp_password', '');
         }
     }
 }
 /**
  * @param \RainLoop\Account $oAccount
  * @param string $sPrevPassword
  * @param string $sNewPassword
  *
  * @return bool
  */
 public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
 {
     if ($this->oLogger) {
         $this->oLogger->Write('ISP: Try to change password for ' . $oAccount->Email());
     }
     $bResult = false;
     if (!empty($this->sDsn) && 0 < \strlen($this->sUser) && 0 < \strlen($this->sPassword) && $oAccount) {
         try {
             $oPdo = new \PDO($this->sDsn, $this->sUser, $this->sPassword);
             $oPdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
             $oStmt = $oPdo->prepare('SELECT password, mailuser_id FROM mail_user WHERE login = ? LIMIT 1');
             if ($oStmt->execute(array($oAccount->IncLogin()))) {
                 $aFetchResult = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
                 if (\is_array($aFetchResult) && isset($aFetchResult[0]['password'], $aFetchResult[0]['mailuser_id'])) {
                     $sDbPassword = \stripslashes($aFetchResult[0]['password']);
                     $sDbSalt = '$1$' . \substr($sDbPassword, 3, 8) . '$';
                     if (\crypt(\stripslashes($sPrevPassword), $sDbSalt) === $sDbPassword) {
                         $oStmt = $oPdo->prepare('UPDATE mail_user SET password = ? WHERE mailuser_id = ?');
                         $bResult = (bool) $oStmt->execute(array($this->cryptPassword($sNewPassword), $aFetchResult[0]['mailuser_id']));
                     }
                 }
             }
         } catch (\Exception $oException) {
             if ($this->oLogger) {
                 $this->oLogger->WriteException($oException);
             }
         }
     }
     return $bResult;
 }
 /**
  * @param \RainLoop\Model\Account $oHmailAccount
  * @param string $sPrevPassword
  * @param string $sNewPassword
  *
  * @return bool
  */
 public function ChangePassword(\RainLoop\Account $oHmailAccount, $sPrevPassword, $sNewPassword)
 {
     if ($this->oLogger) {
         $this->oLogger->Write('Try to change password for ' . $oHmailAccount->Email());
     }
     $bResult = false;
     try {
         $oHmailApp = new COM("hMailServer.Application");
         $oHmailApp->Connect();
         if ($oHmailApp->Authenticate($this->sLogin, $this->sPassword)) {
             $sEmail = $oHmailAccount->Email();
             $sDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail);
             $oHmailDomain = $oHmailApp->Domains->ItemByName($sDomain);
             if ($oHmailDomain) {
                 $oHmailAccount = $oHmailDomain->Accounts->ItemByAddress($sEmail);
                 if ($oHmailAccount) {
                     $oHmailAccount->Password = $sNewPassword;
                     $oHmailAccount->Save();
                     $bResult = true;
                 } else {
                     $this->oLogger->Write('HMAILSERVER: Unknown account (' . $sEmail . ')', \MailSo\Log\Enumerations\Type::ERROR);
                 }
             } else {
                 $this->oLogger->Write('HMAILSERVER: Unknown domain (' . $sDomain . ')', \MailSo\Log\Enumerations\Type::ERROR);
             }
         } else {
             $this->oLogger->Write('HMAILSERVER: Auth error', \MailSo\Log\Enumerations\Type::ERROR);
         }
     } catch (\Exception $oException) {
         if ($this->oLogger) {
             $this->oLogger->WriteException($oException);
         }
     }
     return $bResult;
 }
 /**
  * @param \RainLoop\Model\Account $oAccount
  * @param string $sPrevPassword
  * @param string $sNewPassword
  *
  * @return bool
  */
 public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
 {
     $bResult = false;
     try {
         $sDomain = \MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email());
         $sUserDn = \strtr($this->sUserDnFormat, array('{domain}' => $sDomain, '{domain:dc}' => 'dc=' . \strtr($sDomain, array('.' => ',dc=')), '{email}' => $oAccount->Email(), '{email:user}' => \MailSo\Base\Utils::GetAccountNameFromEmail($oAccount->Email()), '{email:domain}' => $sDomain, '{login}' => $oAccount->Login(), '{imap:login}' => $oAccount->Login(), '{imap:host}' => $oAccount->DomainIncHost(), '{imap:port}' => $oAccount->DomainIncPort()));
         $oCon = @\ldap_connect($this->sHostName);
         if ($oCon) {
             @\ldap_set_option($oCon, LDAP_OPT_PROTOCOL_VERSION, 3);
             if (!@\ldap_bind($oCon, $sUserDn, $sPrevPassword)) {
                 if ($this->oLogger) {
                     $sError = $oCon ? @\ldap_error($oCon) : '';
                     $iErrno = $oCon ? @\ldap_errno($oCon) : 0;
                     $this->oLogger->Write('ldap_bind error: ' . $sError . ' (' . $iErrno . ')', \MailSo\Log\Enumerations\Type::WARNING, 'LDAP');
                 }
                 return false;
             }
         }
         $sEncodedNewPassword = $sNewPassword;
         switch (\strtolower($this->sPasswordEncType)) {
             case 'sha':
                 switch (true) {
                     default:
                     case \function_exists('sha1'):
                         $sEncodedNewPassword = '******' . \base64_encode(\pack('H*', \sha1($sNewPassword)));
                         break;
                     case \function_exists('hash'):
                         $sEncodedNewPassword = '******' . \base64_encode(\hash('sha1', $sNewPassword, true));
                         break;
                     case \function_exists('mhash') && defined('MHASH_SHA1'):
                         $sEncodedNewPassword = '******' . \base64_encode(\mhash(MHASH_SHA1, $sNewPassword));
                         break;
                 }
                 break;
             case 'md5':
                 $sEncodedNewPassword = '******' . \base64_encode(\pack('H*', \md5($sNewPassword)));
                 break;
             case 'crypt':
                 $sEncodedNewPassword = '******' . \crypt($sNewPassword, $this->getSalt(2));
                 break;
         }
         $aEntry = array();
         $aEntry[$this->sPasswordField] = (string) $sEncodedNewPassword;
         if (!!@\ldap_modify($oCon, $sUserDn, $aEntry)) {
             $bResult = true;
         } else {
             if ($this->oLogger) {
                 $sError = $oCon ? @\ldap_error($oCon) : '';
                 $iErrno = $oCon ? @\ldap_errno($oCon) : 0;
                 $this->oLogger->Write('ldap_modify error: ' . $sError . ' (' . $iErrno . ')', \MailSo\Log\Enumerations\Type::WARNING, 'LDAP');
             }
         }
     } catch (\Exception $oException) {
         if ($this->oLogger) {
             $this->oLogger->WriteException($oException, \MailSo\Log\Enumerations\Type::WARNING, 'LDAP');
         }
         $bResult = false;
     }
     return $bResult;
 }
 /**
  * @param \RainLoop\Account $oAccount
  * @param string $sPrevPassword
  * @param string $sNewPassword
  *
  * @return bool
  */
 public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
 {
     if ($this->oLogger) {
         $this->oLogger->Write('Try to change password for ' . $oAccount->Email());
     }
     include_once __DIR__ . '/xmlapi.php';
     $bResult = false;
     if (!empty($this->sHost) && 0 < $this->iPost && 0 < \strlen($this->sUser) && 0 < \strlen($this->sPassword) && $oAccount && \class_exists('xmlapi')) {
         try {
             $oXmlApi = new \xmlapi($this->sHost);
             $oXmlApi->set_port($this->iPost);
             $oXmlApi->set_protocol($this->sSsl ? 'https' : 'http');
             $oXmlApi->set_debug(false);
             $oXmlApi->set_output('json');
             $oXmlApi->set_http_client('curl');
             $oXmlApi->password_auth($this->sUser, $this->sPassword);
             $sEmail = $oAccount->Email();
             $aArgs = array('email' => \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail), 'domain' => \MailSo\Base\Utils::GetDomainFromEmail($sEmail), 'password' => $sNewPassword);
             $sResult = $oXmlApi->api2_query($this->sUser, 'Email', 'passwdpop', $aArgs);
             if ($sResult) {
                 $aResult = @\json_decode($sResult, true);
                 $bResult = isset($aResult['cpanelresult']['data'][0]['result']) && !!$aResult['cpanelresult']['data'][0]['result'];
             }
             if (!$bResult && $this->oLogger) {
                 $this->oLogger->Write('CPANEL: ' . $sResult, \MailSo\Log\Enumerations\Type::ERROR);
             }
         } catch (\Exception $oException) {
             if ($this->oLogger) {
                 $this->oLogger->WriteException($oException);
             }
         }
     }
     return $bResult;
 }
 /**
  * @param \RainLoop\Model\Account $oAccount
  * @param string $sPrevPassword
  * @param string $sNewPassword
  *
  * @return bool
  */
 public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
 {
     $email = $oAccount->Email();
     $username = substr($email, 0, strpos($email, '@'));
     $post = ['username' => $username, 'old_password' => $sPrevPassword, 'new_password' => $sNewPassword];
     $ch = curl_init($this->sUrl);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
     $json = curl_exec($ch);
     curl_close($ch);
     $response = json_decode($json, true);
     if ($response['code'] === 200) {
         $bResult = true;
     } else {
         $bResult = false;
     }
     return $bResult;
 }
 /**
  * @param \RainLoop\Account $oAccount
  * @param string $sPrevPassword
  * @param string $sNewPassword
  *
  * @return bool
  */
 public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
 {
     if ($this->oLogger) {
         $this->oLogger->Write('DirectAdmin: Try to change password for ' . $oAccount->Email());
     }
     $bResult = false;
     if (!empty($this->sHost) && 0 < $this->iPort && $oAccount) {
         $sEmail = \trim(\strtolower($oAccount->Email()));
         $sHost = \trim($this->sHost);
         $sHost = \str_replace('{user:host-imap}', $oAccount->Domain()->IncHost(), $sHost);
         $sHost = \str_replace('{user:host-smtp}', $oAccount->Domain()->OutHost(), $sHost);
         $sHost = \str_replace('{user:domain}', \MailSo\Base\Utils::GetDomainFromEmail($sEmail), $sHost);
         $sHost = \rtrim($this->sHost, '/\\');
         if (!\preg_match('/^http[s]?:\\/\\//i', $sHost)) {
             $sHost = 'http://' . $sHost;
         }
         $sUrl = $sHost . ':' . $this->iPort . '/CMD_CHANGE_EMAIL_PASSWORD';
         $iCode = 0;
         $oHttp = \MailSo\Base\Http::SingletonInstance();
         if ($this->oLogger) {
             $this->oLogger->Write('DirectAdmin[Api Request]:' . $sUrl);
         }
         $mResult = $oHttp->SendPostRequest($sUrl, array('email' => $sEmail, 'oldpassword' => $sPrevPassword, 'password1' => $sNewPassword, 'password2' => $sNewPassword, 'api' => '1'), 'MailSo Http User Agent (v1)', $iCode, $this->oLogger);
         if (false !== $mResult && 200 === $iCode) {
             $aRes = null;
             @\parse_str($mResult, $aRes);
             if (is_array($aRes) && (!isset($aRes['error']) || (int) $aRes['error'] !== 1)) {
                 $bResult = true;
             } else {
                 if ($this->oLogger) {
                     $this->oLogger->Write('DirectAdmin[Error]: Response: ' . $mResult);
                 }
             }
         } else {
             if ($this->oLogger) {
                 $this->oLogger->Write('DirectAdmin[Error]: Empty Response: Code:' . $iCode);
             }
         }
     }
     return $bResult;
 }
 /**
  * @param \RainLoop\Account|string|null $mAccount
  * @param int $iStorageType
  * @param string $sKey
  * @param bool $bMkDir = false
  *
  * @return string
  */
 private function generateFileName($mAccount, $iStorageType, $sKey, $bMkDir = false)
 {
     if (null === $mAccount) {
         $iStorageType = \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY;
     }
     $sEmail = $mAccount instanceof \RainLoop\Account ? \preg_replace('/[^a-z0-9\\-\\.@]+/', '_', ('' === $mAccount->ParentEmail() ? '' : $mAccount->ParentEmail() . '/') . $mAccount->Email()) : '';
     if (\is_string($mAccount) && empty($sEmail)) {
         $sEmail = \preg_replace('/[^a-z0-9\\-\\.@]+/', '_', $mAccount);
     }
     $sTypePath = $sKeyPath = '';
     switch ($iStorageType) {
         default:
         case \RainLoop\Providers\Storage\Enumerations\StorageType::USER:
         case \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY:
             $sTypePath = 'data';
             $sKeyPath = \md5($sKey);
             $sKeyPath = \substr($sKeyPath, 0, 2) . '/' . $sKeyPath;
             break;
         case \RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG:
             $sTypePath = 'cfg';
             $sKeyPath = \preg_replace('/[_]+/', '_', \preg_replace('/[^a-zA-Z0-9\\/]/', '_', $sKey));
             break;
     }
     $sFilePath = '';
     if (\RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY === $iStorageType) {
         $sFilePath = $this->sDataPath . '/' . $sTypePath . '/__nobody__/' . $sKeyPath;
     } else {
         if (!empty($sEmail)) {
             $sFilePath = $this->sDataPath . '/' . $sTypePath . '/' . rtrim(substr($sEmail, 0, 2), '@') . '/' . $sEmail . '/' . $sKeyPath;
         }
     }
     if ($bMkDir && !empty($sFilePath) && !@\is_dir(\dirname($sFilePath))) {
         if (!@\mkdir(\dirname($sFilePath), 0755, true)) {
             throw new \RainLoop\Exceptions\Exception('Can\'t make storage directory "' . $sFilePath . '"');
         }
     }
     return $sFilePath;
 }
 /**
  * @param \RainLoop\Account $oAccount
  * @param string $sPrevPassword
  * @param string $sNewPassword
  *
  * @return bool
  */
 public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
 {
     $bResult = false;
     try {
         $oPoppassdClient = \MailSo\Poppassd\PoppassdClient::NewInstance();
         if ($this->oLogger instanceof \MailSo\Log\Logger) {
             $oPoppassdClient->SetLogger($this->oLogger);
         }
         $oPoppassdClient->Connect($this->sHost, $this->iPort)->Login($oAccount->Login(), $oAccount->Password())->NewPass($sNewPassword)->LogoutAndDisconnect();
         $bResult = true;
     } catch (\Exception $oException) {
         $bResult = false;
     }
     return $bResult;
 }
 /**
  * @param \RainLoop\Account $oAccount
  * @param string $sKey
  * @param bool $bMkDir = false
  *
  * @return string
  */
 private function generateFileName($oAccount, $sKey, $bMkDir = false)
 {
     $sEmail = \preg_replace('/[^a-z0-9\\-\\.@]+/', '_', ('' === $oAccount->ParentEmail() ? '' : $oAccount->ParentEmail() . '/') . $oAccount->Email());
     $sKeyPath = \sha1($sKey);
     $sKeyPath = \substr($sKeyPath, 0, 2) . '/' . \substr($sKeyPath, 2, 2) . '/' . $sKeyPath;
     $sFilePath = $this->sDataPath . '/' . rtrim(substr($sEmail, 0, 2), '@') . '/' . $sEmail . '/' . $sKeyPath;
     if ($bMkDir && !empty($sFilePath) && !@\is_dir(\dirname($sFilePath))) {
         if (!@\mkdir(\dirname($sFilePath), 0755, true)) {
             throw new \RainLoop\Exceptions\Exception('Can\'t make storage directory "' . $sFilePath . '"');
         }
     }
     return $sFilePath;
 }
 /**
  * @param \RainLoop\Model\Account $oAccount
  * @param string $sPrevPassword
  * @param string $sNewPassword
  *
  * @return bool
  */
 public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
 {
     $this->WriteLog('Virtualmin: Try to change password for ' . $oAccount->Email());
     $bResult = false;
     if (!empty($this->sHost) && !empty($this->sAdminUser) && !empty($this->sAdminPassword) && $oAccount) {
         $this->WriteLog('Virtualmin:[Check] Required Fields Present');
         $sEmail = \trim(\strtolower($oAccount->Email()));
         $sEmailUser = \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail);
         $sEmailDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail);
         $sHost = \rtrim(\trim($this->sHost), '/');
         $sUrl = $sHost . '/virtual-server/remote.cgi';
         $sAdminUser = $this->sAdminUser;
         $sAdminPassword = $this->sAdminPassword;
         $iCode = 0;
         $aPost = array('user' => $sEmailUser, 'pass' => $sNewPassword, 'domain' => $sEmailDomain, 'program' => 'modify-user');
         $aOptions = array(CURLOPT_URL => $sUrl, CURLOPT_HEADER => false, CURLOPT_FAILONERROR => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => \http_build_query($aPost, '', '&'), CURLOPT_TIMEOUT => 20, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_USERPWD => $sAdminUser . ':' . $sAdminPassword);
         $oCurl = \curl_init();
         \curl_setopt_array($oCurl, $aOptions);
         $this->WriteLog('Virtualmin: Send post request: ' . $sUrl);
         $mResult = \curl_exec($oCurl);
         $iCode = (int) \curl_getinfo($oCurl, CURLINFO_HTTP_CODE);
         $sContentType = (string) \curl_getinfo($oCurl, CURLINFO_CONTENT_TYPE);
         $this->WriteLog('Virtualmin: Post request result: (Status: ' . $iCode . ', ContentType: ' . $sContentType . ')');
         if (false === $mResult || 200 !== $iCode) {
             $this->WriteLog('Virtualmin: Error: ' . \curl_error($oCurl), \MailSo\Log\Enumerations\Type::WARNING);
         }
         if (\is_resource($oCurl)) {
             \curl_close($oCurl);
         }
         if (false !== $mResult && 200 === $iCode) {
             $aRes = null;
             @\parse_str($mResult, $aRes);
             if (\is_array($aRes) && (!isset($aRes['error']) || (int) $aRes['error'] !== 1)) {
                 $iPos = \strpos($mResult, 'Exit status: ');
                 if ($iPos !== false) {
                     $aStatus = \explode(' ', $mResult);
                     $sStatus = \trim(\array_pop($aStatus));
                     if ('0' === $sStatus) {
                         $this->WriteLog('Virtualmin: Password Change Status: Success');
                         $bResult = true;
                     } else {
                         $this->WriteLog('Virtualmin[Error]: Response: ' . $mResult);
                     }
                 }
             } else {
                 $this->WriteLog('Virtualmin[Error]: Response: ' . $mResult);
             }
         } else {
             $this->WriteLog('Virtualmin[Error]: Empty Response: Code: ' . $iCode);
         }
     }
     return $bResult;
 }
 /**
  * @param \RainLoop\Account $oAccount
  * @param string $sPrevPassword
  * @param string $sNewPassword
  *
  * @return bool
  */
 public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
 {
     if ($this->oLogger) {
         $this->oLogger->Write('Try to change password for ' . $oAccount->Email());
     }
     $bResult = false;
     $dsn = 'mysql:host=' . $this->mHost . ';dbname=' . $this->mDatabase . ';charset=utf8';
     $options = array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
     try {
         $conn = new PDO($dsn, $this->mUser, $this->mPass, $options);
         $select = $conn->prepare("SELECT {$this->mColumn} FROM {$this->mTable} WHERE id = :id LIMIT 1");
         $select->execute(array(':id' => $oAccount->Email()));
         $colCrypt = $select->fetchAll(PDO::FETCH_ASSOC);
         $sCryptPass = $colCrypt[0][$this->mColumn];
         if (0 < strlen($sCryptPass) && crypt($sPrevPassword, $sCryptPass) === $sCryptPass && 7 < mb_strlen($sNewPassword) && 20 > mb_strlen($sNewPassword) && !preg_match('/[^A-Za-z0-9]+/', $sNewPassword)) {
             $update = $conn->prepare("UPDATE {$this->mTable} SET {$this->mColumn} = :crypt WHERE id = :id");
             $update->execute(array(':id' => $oAccount->Email(), ':crypt' => crypt($sNewPassword, '$' . md5(rand()))));
             $bResult = true;
             if ($this->oLogger) {
                 $this->oLogger->Write('Success! Password changed.');
             }
         } else {
             $bResult = false;
             if ($this->oLogger) {
                 $this->oLogger->Write('Something went wrong. Either current password is incorrect, or new password does not match criteria.');
             }
         }
     } catch (\Exception $oException) {
         $bResult = false;
         if ($this->oLogger) {
             $this->oLogger->WriteException($oException);
         }
     }
     return $bResult;
 }
 /**
  * @param \RainLoop\Model\Account $oAccount
  * @param string $sPrevPassword
  * @param string $sNewPassword
  *
  * @return bool
  */
 public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
 {
     if ($this->oLogger) {
         $this->oLogger->Write('Postfix: Try to change password for ' . $oAccount->Email());
     }
     unset($sPrevPassword);
     $bResult = false;
     if (0 < \strlen($sNewPassword)) {
         try {
             $sDsn = 'mysql:host=' . $this->sHost . ';port=' . $this->iPort . ';dbname=' . $this->sDatabase;
             $oPdo = new \PDO($sDsn, $this->sUser, $this->sPassword);
             $oPdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
             $sUpdatePassword = $this->cryptPassword($sNewPassword, $oPdo);
             if (0 < \strlen($sUpdatePassword)) {
                 $oStmt = $oPdo->prepare("UPDATE {$this->sTable} SET {$this->sPasscol} = ? WHERE {$this->sUsercol} = ?");
                 $bResult = (bool) $oStmt->execute(array($sUpdatePassword, $oAccount->Email()));
             } else {
                 if ($this->oLogger) {
                     $this->oLogger->Write('Postfix: Encrypted password is empty', \MailSo\Log\Enumerations\Type::ERROR);
                 }
             }
             $oPdo = null;
         } catch (\Exception $oException) {
             if ($this->oLogger) {
                 $this->oLogger->WriteException($oException);
             }
         }
     }
     return $bResult;
 }
 /**
  * @param \RainLoop\Account $oAccount
  * @param string $sPrevPassword
  * @param string $sNewPassword
  *
  * @return bool
  */
 public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
 {
     if ($this->oLogger) {
         $this->oLogger->Write('Try to change password for ' . $oAccount->Email());
     }
     if (empty($this->mHost) || empty($this->mDatabase) || empty($this->mColumn) || empty($this->mTable)) {
         return false;
     }
     $bResult = false;
     $sDsn = 'mysql:host=' . $this->mHost . ';dbname=' . $this->mDatabase . ';charset=utf8';
     $aOptions = array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
     $sLoginPart = \MailSo\Base\Utils::GetAccountNameFromEmail($oAccount->Email());
     $sDomainPart = \MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email());
     try {
         $oConn = new PDO($sDsn, $this->mUser, $this->mPass, $aOptions);
         $oSelect = $oConn->prepare('SELECT ' . $this->mColumn . ' FROM ' . $this->mTable . ' WHERE pw_name=? AND pw_domain=? LIMIT 1');
         $oSelect->execute(array($sLoginPart, $sDomainPart));
         $aColCrypt = $oSelect->fetchAll(PDO::FETCH_ASSOC);
         $sCryptPass = isset($aColCrypt[0][$this->mColumn]) ? $aColCrypt[0][$this->mColumn] : '';
         if (0 < \strlen($sCryptPass) && \crypt($sPrevPassword, $sCryptPass) === $sCryptPass) {
             $oUpdate = $oConn->prepare('UPDATE ' . $this->mTable . ' SET ' . $this->mColumn . '=ENCRYPT(?,concat("$1$",right(md5(rand()), 8 ),"$")), pw_clear_passwd=\'\' WHERE pw_name=? AND pw_domain=?');
             $oUpdate->execute(array($sNewPassword, $sLoginPart, $sDomainPart));
             $bResult = true;
             if ($this->oLogger) {
                 $this->oLogger->Write('Success! Password changed.');
             }
         } else {
             $bResult = false;
             if ($this->oLogger) {
                 $this->oLogger->Write('Something went wrong. Either current password is incorrect, or new password does not match criteria.');
             }
         }
     } catch (\Exception $oException) {
         $bResult = false;
         if ($this->oLogger) {
             $this->oLogger->WriteException($oException);
         }
     }
     return $bResult;
 }
Beispiel #15
0
 /**
  * @param \RainLoop\Account $oAccount
  */
 public function ClearSignMeData($oAccount)
 {
     if ($oAccount) {
         \RainLoop\Utils::ClearCookie(\RainLoop\Actions::AUTH_SIGN_ME_TOKEN_KEY);
         $this->StorageProvider()->Clear(null, \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY, \RainLoop\KeyPathHelper::SignMeUserToken($oAccount->SignMeToken()));
     }
 }
 /**
  * @param \RainLoop\Account $oAccount
  *
  * @return bool
  */
 public function PasswordChangePossibility($oAccount)
 {
     return $oAccount && $oAccount->Email() && \RainLoop\Plugins\Helper::ValidateWildcardValues($oAccount->Email(), $this->sAllowedEmails);
 }