From 8ce4eef24633701e9ad80f6d8d43a3da702146a6 Mon Sep 17 00:00:00 2001 From: Nikita Petko Date: Wed, 24 Nov 2021 19:39:07 +0000 Subject: [PATCH] Update Activation Dependencies ~ Stop instantiating static classes :(((( ~ Naming styles ~ Using HashingUtility instead of functions.php's genHash thing --- globals/Dependencies/Users/Activation.php | 28 +++++++++++------------ globals/config.php | 5 ++-- globals/userauth.php | 4 ++-- html/activate.php | 7 +++--- html/register.php | 5 ++-- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/globals/Dependencies/Users/Activation.php b/globals/Dependencies/Users/Activation.php index 27757f0..da9f001 100644 --- a/globals/Dependencies/Users/Activation.php +++ b/globals/Dependencies/Users/Activation.php @@ -6,43 +6,41 @@ namespace Alphaland\Users { + use Alphaland\Common\HashingUtiltity; use PDO; class Activation { - private static function generateActivationCode() + private static function GenerateActivationCode() { $hash = ""; - while (true) { - $hash = genHash(32); + do { + $hash = HashingUtiltity::GenerateByteHash(32); - $keycheck = $GLOBALS['pdo']->prepare("SELECT * FROM `alphaland_verification` WHERE `activationcode` = :ac"); + $keycheck = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM `alphaland_verification` WHERE `activationcode` = :ac"); $keycheck->bindParam(":ac", $hash, PDO::PARAM_STR); $keycheck->execute(); - if ($keycheck->rowCount() == 0) { - break; - } - } + } while($keycheck->fetchColumn(0) != 0); return $hash; } - public static function getUserActivationCode(int $userid) + public static function GetUserActivationCode(int $userid) { - $query = $GLOBALS['pdo']->prepare("SELECT * FROM `alphaland_verification` WHERE `uid` = :uid"); + $query = $GLOBALS['pdo']->prepare("SELECT `activationcode` FROM `alphaland_verification` WHERE `uid` = :uid"); $query->bindParam(":uid", $userid, PDO::PARAM_INT); $query->execute(); if ($query->rowCount() == 1) { return $query->fetch(PDO::FETCH_OBJ)->activationcode; } - return false; + return null; } public static function isUserActivated(int $userid) { - $query = $GLOBALS['pdo']->prepare("SELECT * FROM `alphaland_verification` WHERE `isactivated` = 1 AND `uid` = :uid"); + $query = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM `alphaland_verification` WHERE `isactivated` = 1 AND `uid` = :uid"); $query->bindParam(":uid", $userid, PDO::PARAM_INT); $query->execute(); - if ($query->rowCount() > 0) { + if ($query->fetchColumn(0) > 0) { return true; } return false; @@ -50,8 +48,8 @@ namespace Alphaland\Users { public static function setupUserActivation(int $userid) //this should be ran when the user first signs up { - if (!Activation::isUserActivated($userid)) { - $activationcode = Activation::generateActivationCode(); + if (!Activation::IsUserActivated($userid)) { + $activationcode = Activation::GenerateActivationCode(); $n = $GLOBALS['pdo']->prepare("INSERT INTO `alphaland_verification`(`activationcode`,`uid`) VALUES(:ac, :userid)"); $n->bindParam(":ac", $activationcode, PDO::PARAM_STR); diff --git a/globals/config.php b/globals/config.php index f57a512..6f152ee 100644 --- a/globals/config.php +++ b/globals/config.php @@ -10,6 +10,7 @@ my balls yo jaws */ +use Alphaland\Users\Activation; use Alphaland\Users\TwoFactor; try @@ -95,6 +96,7 @@ try include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Users/Activation.php"; include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Users/TwoFactor.php"; include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Moderation/UserModerationManager.php"; + include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Common/HashingUtiltity.php" //authenticator $authenticator = new PHPGangsta_GoogleAuthenticator(); @@ -132,8 +134,7 @@ try forceHttpsCloudflare(); } - $activated = new Alphaland\Users\Activation(); - $activated = $activated::isUserActivated($GLOBALS['user']->id); + $activated = Activation::IsUserActivated($GLOBALS['user']->id); $twofactor = TwoFactor::IsSession2FAUnlocked(); diff --git a/globals/userauth.php b/globals/userauth.php index d66907a..1af1741 100644 --- a/globals/userauth.php +++ b/globals/userauth.php @@ -6,6 +6,7 @@ */ use Alphaland\Moderation\UserModerationManager; +use Alphaland\Users\Activation; class user { public $id = -1; @@ -69,8 +70,7 @@ class user { // .. //activation stuff - $activated = new Alphaland\Users\Activation(); - $activated = $activated::isUserActivated($this->id); + $activated = Activation::IsUserActivated($this->id); //banned $banned = UserModerationManager::IsBanned($this->id); diff --git a/html/activate.php b/html/activate.php index 54567ff..e1450b8 100644 --- a/html/activate.php +++ b/html/activate.php @@ -1,11 +1,12 @@ id)) { +use Alphaland\Users\Activation; + +if (Activation::IsUserActivated($user->id)) { redirect("/"); } -$activationcode = $activation::getUserActivationCode($user->id); +$activationcode = Activation::GetUserActivationCode($user->id); $body = '
diff --git a/html/register.php b/html/register.php index 423929b..c61d8d2 100644 --- a/html/register.php +++ b/html/register.php @@ -5,6 +5,8 @@ TODO: This needs a re-do. This is one of the first pages on this project */ +use Alphaland\Users\Activation; + $body = ''; $error = ''; @@ -130,8 +132,7 @@ else setDefaults($userID); //gives default outfit, body colors and wears the default outfit //setup the activation system - $activation = new Alphaland\Users\Activation(); - $activation::setupUserActivation($userID); + Activation::SetupUserActivation($userID); //create new session createSession($userID);