-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.php
More file actions
110 lines (106 loc) · 4.32 KB
/
process.php
File metadata and controls
110 lines (106 loc) · 4.32 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
ob_start();
require_once("connection.php");
require_once("functions.php");
$error=array();
if(isset($_POST['login'])){
$email = htmlspecialchars($_POST['email']);
$password = htmlspecialchars($_POST['password']);
if(empty($email)){
array_push($error, "Email is Required");
}
if(empty($password)){
array_push($error, "Password is Required");
}
if(empty($error)){
$query = "SELECT * FROM users WHERE email = '$email'";
$run_query = mysqli_query($connection, $query);
if($run_query==true){
session_start();
while($result = mysqli_fetch_assoc($run_query)){
//check if password is correct
$passwordcorrect = password_verify($password, $result["password"]);
if($passwordcorrect==true){
$user_id = $result["id"];
$_SESSION["user"] = $user_id;
die(header("Location: dashboard.php"));
}else{
array_push($error,"Please check if your Email Password is correct");
}
}
}else{
array_push($error,"Login Failed please check if your Email or Password is correct");
}
}
}
if(isset($_POST['forgot'])){
$email = htmlspecialchars($_POST['email']);
$password = htmlspecialchars($_POST['password']);
if(empty($email)){
array_push($error, "Email is Required");
}
if(empty($password)){
array_push($error, "Password is Required");
}
if(empty($error)){
$query = "SELECT * FROM users WHERE email = '$email'";
$run_query = mysqli_query($connection, $query);
if(mysqli_num_rows($run_query)==1){
//check if password is correct
$passwordhash = password_hash($_POST['password'], PASSWORD_DEFAULT);
$data_array=[
'password' =>$passwordhash,
];
//implode arrays the insert
$columns = implode(", ",array_keys($data_array));
$escaped_values = array_map(array($connection, 'real_escape_string'),array_values($data_array));
$values = implode("', '", $escaped_values);
$sql = "UPDATE users SET $columns='$values' where email='$email'";
$run_query = mysqli_query($connection, $sql);
if($run_query == true){
array_push($error, "Password Successfully updated");
die(header('Location: index.php'));
}else{
array_push($error, "Error updating password");
}
}else{
array_push($error,"Email does not exist");
}
}
}
if(isset($_POST['register'])){
$email = htmlspecialchars($_POST['email']);
$fullname = htmlspecialchars($_POST['fullname']);
$password = $_POST['password'];
if(empty($email)){
array_push($error, "Email is Required");
}
if(empty($password)){
array_push($error, "Password is Required");
}
if(empty($fullname)){
array_push($error, "Fullname is Required");
}
if(empty($error)){
$hashedpassword = password_hash($_POST['password'], PASSWORD_DEFAULT);
//Data array to save
$data_array=[
'email' =>$email,
'password' =>$hashedpassword,
'fullname' =>$fullname,
];
//implode arrays the insert
$columns = implode(", ",array_keys($data_array));
$escaped_values = array_map(array($connection, 'real_escape_string'),array_values($data_array));
$values = implode("', '", $escaped_values);
$sql = "INSERT INTO users($columns) VALUES ('$values')";
$run_query = mysqli_query($connection, $sql);
if($run_query == true){
array_push($error, "Registered Successfully");
die(header('Location: index.php'));
}else{
array_push($error, "Registered Successfully");
}
}
}
?>