2015-01-09 09:22:31 +01:00
|
|
|
<?php
|
|
|
|
namespace Framadate\Security;
|
|
|
|
|
|
|
|
class Token {
|
|
|
|
|
|
|
|
private $time;
|
|
|
|
private $value;
|
|
|
|
|
2015-01-10 16:35:21 +01:00
|
|
|
function __construct() {
|
|
|
|
$this->time = time() + TOKEN_TIME;
|
|
|
|
$this->value = $this->generate();
|
2015-01-09 09:22:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function generate() {
|
2015-01-10 16:35:21 +01:00
|
|
|
return sha1(uniqid(mt_rand(), true));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTime() {
|
|
|
|
return $this->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getValue() {
|
|
|
|
return $this->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isGone() {
|
|
|
|
return $this->time < time();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function check($value) {
|
|
|
|
return $value === $this->value;
|
2015-01-09 09:22:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|