Mail auth WIP

This commit is contained in:
Fred Tempez 2023-03-26 16:22:02 +02:00
parent ca87ee2d3b
commit 53b78bf61d
4 changed files with 6 additions and 32 deletions

View File

@ -682,28 +682,4 @@ class helper
return $text;
}
/**
* Cryptage
* @param string $key la clé d'encryptage
* @param string $payload la chaine à coder
* @return string
*/
public static function encrypt($key, $payload)
{
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
$encrypted = openssl_encrypt($payload, 'aes-256-cbc', $key, 0, $iv);
return base64_encode($encrypted . '::' . $iv);
}
/**
* Décryptage
* @param string $key la clé d'encryptage
* @param string $garble la chaine à décoder
* @return string
*/
public static function decrypt($key, $garble)
{
list($encrypted_data, $iv) = explode('::', base64_decode($garble), 2);
return openssl_decrypt($encrypted_data, 'aes-256-cbc', $key, 0, $iv);
}
}

View File

@ -1146,12 +1146,10 @@ class common
$mail->Host = $this->getdata(['config', 'smtp', 'host']);
$mail->Port = (int) $this->getdata(['config', 'smtp', 'port']);
if ($this->getData(['config', 'smtp', 'auth'])) {
$mail->SMTPAutoTLS = true;
$mail->SMTPSecure = true;
$mail->SMTPAuth = $this->getData(['config', 'smtp', 'auth']);
$mail->Username = $this->getData(['config', 'smtp', 'username']);
$mail->Password = helper::decrypt($this->getData(['config', 'smtp', 'username']), $this->getData(['config', 'smtp', 'password']));
$mail->SMTPSecure = $this->getData(['config', 'smtp', 'secure']);
$mail->Password = $this->getData(['config', 'smtp', 'password']);
}
}

View File

@ -455,12 +455,12 @@ class config extends common
],
'smtp' => [
'enable' => $this->getInput('smtpEnable', helper::FILTER_BOOLEAN),
'host' => $this->getInput('smtpHost', helper::FILTER_STRING_SHORT, $this->getInput('smtpEnable', helper::FILTER_BOOLEAN)),
'port' => $this->getInput('smtpPort', helper::FILTER_INT, $this->getInput('smtpEnable', helper::FILTER_BOOLEAN)),
'host' => $this->getInput('smtpHost', helper::FILTER_STRING_SHORT),
'port' => $this->getInput('smtpPort', helper::FILTER_INT),
'auth' => $this->getInput('smtpAuth', helper::FILTER_BOOLEAN),
'secure' => $this->getInput('smtpSecure', helper::FILTER_STRING_SHORT),
'username' => $this->getInput('smtpUsername', helper::FILTER_STRING_SHORT, $this->getInput('smtpAuth', helper::FILTER_BOOLEAN)),
'password' => helper::encrypt($this->getData(['config', 'smtp', 'username']), $this->getInput('smtpPassword', null, $this->getInput('smtpAuth', helper::FILTER_BOOLEAN))),
'username' => $this->getInput('smtpUsername', helper::FILTER_STRING_SHORT),
'password' => $this->getInput('smtpPassword', helper::FILTER_STRING_SHORT),
'from' => $this->getInput('smtpFrom', helper::FILTER_MAIL, true),
],
'seo' => [

View File

@ -491,7 +491,7 @@ class form extends common
$this->addOutput([
'notification' => ($sent === true ? helper::translate('Formulaire soumis') : $sent),
'redirect' => $redirect ? helper::baseUrl() . $redirect : '',
'state' => ($sent === true ? true : null),
'state' => ($sent === true ? true : false),
'vendor' => [
'flatpickr'
],