WebServ/www/public/M4/02/userManipulation.php

47 lines
1.0 KiB
PHP
Raw Permalink Normal View History

2024-09-09 12:19:57 +00:00
<!DOCTYPE html>
<html lang="se">
<head>
<meta charset="UTF-8">
<title>Person write</title>
</head>
<body>
<?php
include("User.php");
function addUser($user)
{
2024-09-13 12:56:16 +00:00
$file = "../../../userData/M4-02-users.dat";
2024-09-09 12:19:57 +00:00
if(file_exists($file)) {
$users = unserialize(file_get_contents($file));
$users[] = $user;
file_put_contents($file, serialize($users));
}
else {
$users = array();
$users[] = $user;
file_put_contents($file, serialize($users));
}
}
function isPresent($userToFind)
{
2024-09-13 12:56:16 +00:00
$file = "../../../userData/M4-02-users.dat";
2024-09-09 12:19:57 +00:00
if (file_exists($file)) {
$userArray = unserialize(file_get_contents($file));
}
else return false;
foreach($userArray as $user) {
if($userToFind->getUsername() == $user->getUsername() && password_verify($userToFind->getPassword(), $user->getPassword())) return true;
}
return false;
}
?>
</body>
</html>