mirror of
https://github.com/simon987/Much-Assembly-Required-Frontend.git
synced 2025-12-15 07:39:03 +00:00
Initial commit
This commit is contained in:
35
include/TokenManager.php
Normal file
35
include/TokenManager.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
include_once "include/SqlConnection.php";
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
class TokenManager
|
||||
{
|
||||
/**
|
||||
* @param $user string Generate an authentication token for a user
|
||||
* @return string token
|
||||
*/
|
||||
public static function generateToken($user)
|
||||
{
|
||||
|
||||
$token = bin2hex(openssl_random_pseudo_bytes(64));
|
||||
|
||||
$conn = new SqlConnection();
|
||||
|
||||
$stmt_update = $conn->prepare("UPDATE mar_user SET authToken=?, tokenTime=NOW() WHERE username=?");
|
||||
$stmt_update->bindValue(1, $token);
|
||||
$stmt_update->bindValue(2, $user);
|
||||
$stmt_update->execute();
|
||||
|
||||
return $token;
|
||||
|
||||
}
|
||||
|
||||
public static function generateEmptyToken()
|
||||
{
|
||||
return "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user