mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 04:59:21 +03:00
Also removed: POP3, OAuth2 and update feature Added: admin password_hash/password_verify Requires: PHP 7.3+ Replaced: CRLF with LF Replaced: pclZip with ZipArchive
81 lines
2.1 KiB
PHP
81 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace RainLoop\Providers;
|
|
|
|
class ChangePassword extends \RainLoop\Providers\AbstractProvider
|
|
{
|
|
/**
|
|
* @var \RainLoop\Actions
|
|
*/
|
|
private $oActions;
|
|
|
|
/**
|
|
* @var \RainLoop\Providers\ChangePassword\ChangePasswordInterface
|
|
*/
|
|
private $oDriver;
|
|
|
|
/**
|
|
* @var bool
|
|
*/
|
|
private $bCheckWeak;
|
|
|
|
public function __construct(\RainLoop\Actions $oActions, ?\RainLoop\Providers\ChangePassword\ChangePasswordInterface $oDriver = null, bool $bCheckWeak = true)
|
|
{
|
|
$this->oActions = $oActions;
|
|
$this->oDriver = $oDriver;
|
|
$this->bCheckWeak = $bCheckWeak;
|
|
}
|
|
|
|
public function PasswordChangePossibility(\RainLoop\Model\Account $oAccount) : bool
|
|
{
|
|
return $this->IsActive() &&
|
|
$this->oDriver && $this->oDriver->PasswordChangePossibility($oAccount)
|
|
;
|
|
}
|
|
|
|
public function ChangePassword(\RainLoop\Model\Account $oAccount, string $sPrevPassword, string $sNewPassword)
|
|
{
|
|
$mResult = false;
|
|
|
|
if ($this->oDriver instanceof \RainLoop\Providers\ChangePassword\ChangePasswordInterface &&
|
|
$this->PasswordChangePossibility($oAccount))
|
|
{
|
|
if ($sPrevPassword !== $oAccount->Password())
|
|
{
|
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CurrentPasswordIncorrect);
|
|
}
|
|
|
|
$sPasswordForCheck = \trim($sNewPassword);
|
|
if (6 > \strlen($sPasswordForCheck))
|
|
{
|
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::NewPasswordShort);
|
|
}
|
|
|
|
if (!\MailSo\Base\Utils::PasswordWeaknessCheck($sPasswordForCheck))
|
|
{
|
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::NewPasswordWeak);
|
|
}
|
|
|
|
if (!$this->oDriver->ChangePassword($oAccount, $sPrevPassword, $sNewPassword))
|
|
{
|
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CouldNotSaveNewPassword);
|
|
}
|
|
|
|
$oAccount->SetPassword($sNewPassword);
|
|
$this->oActions->SetAuthToken($oAccount);
|
|
|
|
$mResult = $this->oActions->GetSpecAuthToken();
|
|
}
|
|
else
|
|
{
|
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CouldNotSaveNewPassword);
|
|
}
|
|
|
|
return $mResult;
|
|
}
|
|
|
|
public function IsActive() : bool
|
|
{
|
|
return $this->oDriver instanceof \RainLoop\Providers\ChangePassword\ChangePasswordInterface;
|
|
}
|
|
}
|