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']))
);
$formData['data']['deviceName'] ?: $defaultName,
$formData['data']['secret'],
$formData['data']['code']['minCounter'],
- TIME_NOW,
+ \TIME_NOW,
]);
}
}
AND minCounter < ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute([
- TIME_NOW,
+ \TIME_NOW,
$formData['data']['code']['minCounter'],
$setupId,
$formData['data']['deviceID'],
((\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;
}
* 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);