Email impl
This commit is contained in:
parent
4b3aceebd7
commit
2be9ed5c01
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
Alphaland 2021
|
||||
*/
|
||||
|
||||
namespace Alphaland\Common {
|
||||
|
||||
use PDO;
|
||||
|
||||
class Email
|
||||
{
|
||||
public static function ObfuscateEmail(string $email)
|
||||
{
|
||||
$em = explode("@",$email);
|
||||
$name = implode('@', array_slice($em, 0, count($em)-1));
|
||||
$len = floor(strlen($name)/2);
|
||||
return substr($name,0, $len) . str_repeat('.', $len) . "@" . end($em);
|
||||
}
|
||||
|
||||
public static function GenerateVerificationEmailHash(int $len)
|
||||
{
|
||||
$hash = "";
|
||||
do {
|
||||
$hash = HashingUtiltity::GenerateByteHash($len);
|
||||
$tokencheck = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM verify_email_keys WHERE token = :t");
|
||||
$tokencheck->bindParam(":t", $hash, PDO::PARAM_STR);
|
||||
$tokencheck->execute();
|
||||
} while ($tokencheck->fetchColumn() != 0);
|
||||
return $hash;
|
||||
}
|
||||
|
||||
public static function GenerateResetPasswordHash(int $len)
|
||||
{
|
||||
$hash = "";
|
||||
do {
|
||||
$hash = HashingUtiltity::GenerateByteHash($len);
|
||||
$tokencheck = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM password_reset_keys WHERE token = :t");
|
||||
$tokencheck->bindParam(":t", $hash, PDO::PARAM_STR);
|
||||
$tokencheck->execute();
|
||||
} while ($tokencheck->fetchColumn() != 0);
|
||||
return $hash;
|
||||
}
|
||||
|
||||
public static function IsEmailRegistered(string $email)
|
||||
{
|
||||
$check = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM users WHERE email = :e");
|
||||
$check->bindParam(":e", $email, PDO::PARAM_STR);
|
||||
$check->execute();
|
||||
if ($check->fetchColumn() > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
use Alphaland\Administration\SignupKey;
|
||||
use Alphaland\Common\Email;
|
||||
use Alphaland\Moderation\Filter;
|
||||
use Alphaland\Users\Activation;
|
||||
use Alphaland\Users\ReferralProgram;
|
||||
|
|
@ -77,7 +78,7 @@ else
|
|||
$error = '<div class="alert alert-danger" role="alert">The email you entered is invalid</div>';
|
||||
}
|
||||
|
||||
if (emailRegistered($email))
|
||||
if (Email::IsEmailRegistered($email))
|
||||
{
|
||||
$error = "Email is already registered";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue