hanyuu/src/Users/UserTOTPInfo.php

39 lines
988 B
PHP
Raw Permalink Normal View History

2023-01-09 21:44:34 +00:00
<?php
2023-10-20 22:11:43 +00:00
namespace Hanyuu\Users;
2023-01-09 21:44:34 +00:00
use Index\DateTime;
use Index\Data\IDbResult;
2023-10-20 22:11:43 +00:00
use Hanyuu\TOTPGenerator;
2023-01-09 21:44:34 +00:00
2023-10-20 22:11:43 +00:00
class UserTOTPInfo {
2023-01-09 21:44:34 +00:00
private string $userId;
private string $secretKey;
private DateTime $changed;
public function __construct(IDbResult $result) {
$this->userId = $result->getString(0);
$this->secretKey = $result->getString(1);
$this->changed = DateTime::fromUnixTimeSeconds($result->getInteger(2));
}
public function getUserId(): string {
return $this->userId;
}
public function getSecretKey(): string {
return $this->secretKey;
}
public function getChangedTime(): DateTime {
return $this->changed;
}
public function createGenerator(): TOTPGenerator {
return new TOTPGenerator($this->secretKey);
}
2023-10-18 10:34:30 +00:00
2023-10-20 22:11:43 +00:00
public function generateValidCodes(int $range = 1, ?int $timecode = null): array {
return $this->createGenerator()->generateRange($range, $timecode);
2023-10-18 10:34:30 +00:00
}
2023-01-09 21:44:34 +00:00
}