From 006d56fc8c2d6ffeffa82a7e9ad1ce8437fb9e48 Mon Sep 17 00:00:00 2001 From: Astrologies Date: Wed, 22 Dec 2021 05:45:24 -0500 Subject: [PATCH] TwoFactor impl update --- globals/Dependencies/Users/TwoFactor.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/globals/Dependencies/Users/TwoFactor.php b/globals/Dependencies/Users/TwoFactor.php index 6c11a20..16268c9 100644 --- a/globals/Dependencies/Users/TwoFactor.php +++ b/globals/Dependencies/Users/TwoFactor.php @@ -4,9 +4,6 @@ Alphaland 2021 */ -// Astro, please make public members start with capital letters -// Also where you aren't actually fetching data, please make it do a COUNT(*) - namespace Alphaland\Users { use PDO; @@ -18,10 +15,10 @@ namespace Alphaland\Users { $secret = ""; do { $secret = $GLOBALS['authenticator']->createSecret(); - $keycheck = $GLOBALS['pdo']->prepare("SELECT * FROM `twofactor` WHERE `secret` = :ac"); + $keycheck = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM `twofactor` WHERE `secret` = :ac"); $keycheck->bindParam(":ac", $secret, PDO::PARAM_STR); $keycheck->execute(); - } while ($keycheck->rowCount() != 0); + } while ($keycheck->fetchColumn() != 0); return $secret; } @@ -71,10 +68,10 @@ namespace Alphaland\Users { public static function Is2FAInitialized(int $userid) { - $isinit = $GLOBALS['pdo']->prepare("SELECT * FROM `twofactor` WHERE `validated` = 1 AND `userid` = :uid"); + $isinit = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM `twofactor` WHERE `validated` = 1 AND `userid` = :uid"); $isinit->bindParam(":uid", $userid, PDO::PARAM_INT); $isinit->execute(); - if ($isinit->rowCount() > 0) { + if ($isinit->fetchColumn() > 0) { return true; } return false; @@ -137,10 +134,10 @@ namespace Alphaland\Users { { $localuser = $GLOBALS['user']->id; $session = $GLOBALS['user']->sessionCookieID; - $check = $GLOBALS['pdo']->prepare("SELECT * FROM `sessions` WHERE `twoFactorUnlocked` = 1 AND `id` = :session"); + $check = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM `sessions` WHERE `twoFactorUnlocked` = 1 AND `id` = :session"); $check->bindParam(":session", $session, PDO::PARAM_INT); $check->execute(); - if ($check->rowCount() > 0 || !TwoFactor::Is2FAInitialized($localuser)) { + if ($check->fetchColumn() > 0 || !TwoFactor::Is2FAInitialized($localuser)) { return true; } return false;