Add namespace to all functions and constants for TotpMultifactorMethod
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 9 Nov 2020 12:40:36 +0000 (13:40 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 16 Nov 2020 16:29:04 +0000 (17:29 +0100)
wcfsetup/install/files/lib/system/user/multifactor/TotpMultifactorMethod.class.php
wcfsetup/install/files/lib/system/user/multifactor/totp/Totp.class.php

index 76df9b4d9b913500afb8763cdfaf29a548eb372d..dffca00603e4435cc105c1323bcad9094f8724eb 100644 (file)
@@ -113,7 +113,7 @@ class TotpMultifactorMethod implements IMultifactorMethod {
        public function processManagementForm(IFormDocument $form, int $setupId): void {
                $formData = $form->getData();
                
-               assert(
+               \assert(
                        (!empty($formData['data']) && empty($formData['delete'])) ||
                        (empty($formData['data']) && !empty($formData['delete']))
                );
@@ -152,7 +152,7 @@ class TotpMultifactorMethod implements IMultifactorMethod {
                                $formData['data']['deviceName'] ?: $defaultName,
                                $formData['data']['secret'],
                                $formData['data']['code']['minCounter'],
-                               TIME_NOW,
+                               \TIME_NOW,
                        ]);
                }
        }
@@ -255,7 +255,7 @@ class TotpMultifactorMethod implements IMultifactorMethod {
                                AND     minCounter < ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute([
-                       TIME_NOW,
+                       \TIME_NOW,
                        $formData['data']['code']['minCounter'],
                        $setupId,
                        $formData['data']['deviceID'],
index f512549bf56fee30144f8a294f0fae0332beb231..eeedaafc0e63c6b9f96b1fe9e2be2a4774fc4cfe 100644 (file)
@@ -56,7 +56,7 @@ final class Totp {
                        ((\ord($hash[$offset + 2]) & 0xff) << 8) |
                        ((\ord($hash[$offset + 3]) & 0xff) << 0);
                
-               $otp = \str_pad($binary % \pow(10, self::CODE_LENGTH), self::CODE_LENGTH, "0", \STR_PAD_LEFT);
+               $otp = \str_pad($binary % (10 ** self::CODE_LENGTH), self::CODE_LENGTH, "0", \STR_PAD_LEFT);
                
                return $otp;
        }
@@ -77,7 +77,7 @@ final class Totp {
         * was used for verification. You MUST store the updated $minCounter to prevent code re-use.
         */
        public function validateTotpCode(string $userCode, int &$minCounter, \DateTime $time): bool {
-               $counter = intval($time->getTimestamp() / self::TIME_STEP);
+               $counter = \intval($time->getTimestamp() / self::TIME_STEP);
                
                for ($offset = -self::LEEWAY; $offset < self::LEEWAY; $offset++) {
                        $possibleCode = $this->generateHotpCode($counter + $offset);