38 lines
829 B
PHP
38 lines
829 B
PHP
<?php
|
|
namespace api;
|
|
use PDO;
|
|
|
|
require_once "./config.php";
|
|
|
|
/**
|
|
* User Class
|
|
* Define all functions which either check, update or delete user data
|
|
*/
|
|
class user
|
|
{
|
|
function checkUser($username, $password): bool
|
|
{
|
|
$conn = dbConn();
|
|
$stmt = $conn->prepare("SELECT * FROM users WHERE username = :username");
|
|
$stmt->bindParam(":username", $username);
|
|
$stmt->execute();
|
|
|
|
// set the resulting array to associative
|
|
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if ($result)
|
|
{
|
|
if (password_verify($password, $result[0]["password"]))
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function createToken(): string
|
|
{
|
|
return uniqid("rpe-");
|
|
}
|
|
} |