Potential Produkt Increment #83

Merged
mg8220s merged 40 commits from dev into main 2024-12-11 14:16:27 +01:00
3 changed files with 53 additions and 3 deletions
Showing only changes of commit 5e87a8654c - Show all commits

View File

@@ -36,6 +36,10 @@ class User
*/
public static function createUser(string $username, string $password): User|false
{
if(self::getFromUsername($username) !== false) {
return false;
}
if(strlen($username) > 100) {
return false;
}
@@ -141,6 +145,54 @@ class User
}
fclose($file);
unset($this->username);
unset($this->passwordHash);
return true;
}
/**
* Ändert das Passwort des Accounts
* @param string $oldPassword altes Passwort
* @param string $newPassword Neues Passwort
* @return bool true, wenn erfolgreich geändert, sonst false
*/
public function changePassword(string $oldPassword, string $newPassword): bool
{
if(!$this->isPasswordCorrect($oldPassword)) {
return false;
}
if(!$this->logout()) {
return false;
}
$file = fopen(self::$userdataDirectory . self::$userdataFile, "c+");
if(!$file) {
return false;
}
$this->passwordHash = password_hash($newPassword, PASSWORD_ARGON2I);
$lastLine = ftell($file);
while (($data = fgetcsv($file, 300)) !== false) {
if (count($data) != 2) {
} else if ($data[0] !== $this->username) {
} else {
$data[1] = $this->passwordHash;
fseek($file, $lastLine);
fputcsv($file, $data);
break;
}
$lastLine = ftell($file);
}
fclose($file);
return true;
}
@@ -191,7 +243,6 @@ class User
if(time() - $_SESSION["login_time"] > 86400 * 5) {
session_unset();
session_destroy();
return false;
}
@@ -211,7 +262,6 @@ class User
}
session_unset();
session_destroy();
return true;
}

View File

@@ -1 +0,0 @@
<?php

1
webseite/users/users.csv Normal file
View File

@@ -0,0 +1 @@
admin,"$argon2i$v=19$m=65536,t=4,p=1$Wi9oVlZ2UjFFVUFTVDBYbg$fgYAK05urgS2+38wFPa9k1oO27O5B/J0CSWB7mUCYGU"
1 admin $argon2i$v=19$m=65536,t=4,p=1$Wi9oVlZ2UjFFVUFTVDBYbg$fgYAK05urgS2+38wFPa9k1oO27O5B/J0CSWB7mUCYGU