39 lines
988 B
PHP
39 lines
988 B
PHP
<?php
|
|
namespace Hanyuu\Users;
|
|
|
|
use Index\DateTime;
|
|
use Index\Data\IDbResult;
|
|
use Hanyuu\TOTPGenerator;
|
|
|
|
class UserTOTPInfo {
|
|
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);
|
|
}
|
|
|
|
public function generateValidCodes(int $range = 1, ?int $timecode = null): array {
|
|
return $this->createGenerator()->generateRange($range, $timecode);
|
|
}
|
|
}
|