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

47 lines
1.0 KiB
PHP
Raw 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)
{
$file = "../../../M4-02-users.dat";
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)
{
$file = "../../../M4-02-users.dat";
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>