-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.php
30 lines (23 loc) · 1.09 KB
/
user.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
function addUser(PDO $pdo, $first_name, $last_name, $email, $password, $role = "user") {
$sql = "INSERT INTO `users` (`first_name`, `last_name`, `email`, `password`, `role`) VALUES (:first_name, :last_name, :email, :password, :role);";
$query = $pdo->prepare($sql);
$password = password_hash($password, PASSWORD_DEFAULT);
$query->bindParam(':first_name', $first_name, PDO::PARAM_STR);
$query->bindParam(':last_name', $last_name, PDO::PARAM_STR);
$query->bindParam(':email', $email, PDO::PARAM_STR);
$query->bindParam(':password', $password, PDO::PARAM_STR);
$query->bindParam(':role', $role, PDO::PARAM_STR);
return $query->execute();
}
function verifyUserLoginPassword(PDO $pdo, string $email, string $password) {
$query = $pdo->prepare("SELECT * FROM users WHERE email = :email");
$query->bindParam(':email', $email, PDO::PARAM_STR);
$query->execute();
$user = $query->fetch();
if ($user && password_verify($password, $user['password'])) {
return $user;
} else {
return false;
}
}