Skip to content

Commit 70c2429

Browse files
committed
Form token functions
1 parent 5b55c90 commit 70c2429

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/SecureFuncs.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ public static function encrypt($input, $key = false)
5050
return array('Key' => $key, 'Encrypted' => $ciphertext);
5151
}
5252

53+
/**
54+
* Checks if the given id and token match > If not the form has been sent twice or the ID is incorrect
55+
* @param $id
56+
* @return md5hash
57+
*/
58+
public function getFormToken($id, $token)
59+
{
60+
if (empty($_SESSION['formtoken'][$id])) {
61+
return false;
62+
}
63+
return md5($_SESSION['formtoken'][$id]) == $token;
64+
}
65+
5366
/**
5467
* @param $password -> password to hash
5568
* @return bool|string
@@ -69,6 +82,17 @@ public static function password_verify($password, $hash)
6982
return password_verify(base64_encode(hash('sha256', $password, true)), $hash);
7083
}
7184

85+
/**
86+
* Sets a new random token using the given id
87+
* @param $id
88+
* @return md5hash
89+
*/
90+
public function setFormToken($id)
91+
{
92+
$_SESSION['formtoken'][$id] = $this->randomString(100);
93+
return md5($_SESSION['formtoken'][$id]);
94+
}
95+
7296
/**
7397
* @param int $length
7498
* @return string

0 commit comments

Comments
 (0)