mirror of
https://github.com/michaelstaake/mainty.git
synced 2026-04-16 19:40:13 +00:00
Initial version upload
This commit is contained in:
36
models/User.php
Normal file
36
models/User.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
class User {
|
||||
private PDO $db;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = Database::getInstance();
|
||||
}
|
||||
|
||||
public function verifyPassword(string $password): bool {
|
||||
$stmt = $this->db->query("SELECT password_hash FROM users LIMIT 1");
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if (!$user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return password_verify($password, $user['password_hash']);
|
||||
}
|
||||
|
||||
public function updatePassword(string $newPassword): bool {
|
||||
try {
|
||||
$stmt = $this->db->prepare("UPDATE users SET password_hash = ?, updated_at = CURRENT_TIMESTAMP");
|
||||
return $stmt->execute([password_hash($newPassword, PASSWORD_DEFAULT)]);
|
||||
} catch (PDOException $e) {
|
||||
error_log('Password update failed: ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getId(): ?int {
|
||||
$stmt = $this->db->query("SELECT id FROM users LIMIT 1");
|
||||
$user = $stmt->fetch();
|
||||
return $user ? (int)$user['id'] : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user