12 protected function hash($context,$token){
13 return substr(base_convert(sha1(serialize($context) . $this->
component(
'encrypt')->key . $token),16,36),0,$this->length / 2);
21 public function generate($context = null,$ttl = null){
22 $token = $ttl ? base_convert(time() + $ttl,10,36) .
'-' :
'';
23 $token .= \Rsi\Str::random($this->length / 2 - strlen($token) - 1,
'[0-9][a-z]');
24 return $token .
'-' . $this->
hash($context,$token);
32 public function valid($token,$context = null){
35 if(strlen($token) == $this->length)
switch(count($token = explode(
'-',$token))){
37 if(base_convert($token[0],36,10) < time())
break;
39 $hash = array_pop($token);
40 $result = hash_equals($this->
hash($context,implode(
'-',$token)),$hash);
44 if($this->_fred->debug)
throw $e;
46 $this->
component(
'security')->bruteForceDelay($result,
'token');
53 public function delete($token){
valid($token, $context=null)
Check if a token is (still) valid.
Unique token generator/validator.
generate($context=null, $ttl=null)
Generate a token.
component($name)
Get a component (local or default).