-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify.php
More file actions
53 lines (44 loc) · 1.19 KB
/
verify.php
File metadata and controls
53 lines (44 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?
// Cryptoblog Token-based Verifier Class
// Copyleft by Elemential 2015
// Licensed under LGPL 3.0
require_once("config.php");
class CryptoblogVerifier
{
private $prefix;
private $con;
public function __construct($prefix)
{
$this -> prefix = $prefix;
$this -> con = CryptoblogConfig::getConnection();
}
public function verify($key,$token,$signature)
{
$query = sprintf(
"SELECT time
FROM %1\$sverifications
WHERE token='%2\$s'",
$this->prefix,
$this -> con -> real_escape_string($token)
);
$result = $this -> con -> query($query);
$valid = ! $result -> num_rows;
if($valid)
{
$key_valid = openssl_verify($token, hex2bin($signature), $key, OPENSSL_ALGO_MD5);
if($key_valid)
{
$query = sprintf(
"INSERT INTO %1\$sverifications(token)
VALUES (
'%2\$s'
)",
$this->prefix,
$this -> con -> real_escape_string($token));
$result = $this -> con -> query($query);
}
}
return $valid && $key_valid;
}
}
?>