forked from epospiky/hng-login
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.php
More file actions
83 lines (67 loc) · 2.51 KB
/
Copy pathprocess.php
File metadata and controls
83 lines (67 loc) · 2.51 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
<?php
require 'db_config.php';
if (isset($_POST['login'])) {
$email = $_POST['email'];
$password = $_POST['password'];
if (!empty($email) && !empty($password)) {
$password = md5($password);
$stmt = $conn->prepare("SELECT * FROM user WHERE email = ? AND password = ?");
$stmt->bindParam(1, $email, PDO::PARAM_STR);
$stmt->bindParam(2, $password, PDO::PARAM_STR);
$stmt->execute();
$row = $stmt->fetch();
if ($row > 0) {;?>
<link rel="stylesheet" type="text/css" href="style.css">
<div class="success-login">
<h2>Congratulations! You have been successfully authenticated</h2>
<p>You username is <?php echo " ".$row['Username'];?></p>
<p>Your Email address is <?php echo " ".$row['Email'];?></p>
</div>
<?php } else {
echo "<script>alert('Invalid Email and password!')</script>";
echo "<script>window.location.href='login.html'</script>";
}
} else {
echo "<script>alert('Please fill in all fields!')</script>";
}
};
if (isset($_POST['signup'])) {
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
if (!empty($firstname) &&!empty($lastname) &&!empty($email) &&!empty($password) &&!empty($cpassword)) {
if ($password == $cpassword) {
$stmt = $conn->prepare("SELECT * FROM user WHERE Email = ?");
$stmt->bindParam(1, $email, PDO::PARAM_STR);
$stmt->execute();
$row = $stmt->fetch();
if ( $row > 0) {
echo "<script>alert('Username already exists. Please login!')</script>";
} else {
$password = md5($password);
$stmt = $conn->prepare("INSERT INTO user (Firstname, Lastname, Email, Password) VALUES (?,?,?,?)");
$stmt->bindParam(1, $firstname, PDO::PARAM_STR);
$stmt->bindParam(2, $lastname, PDO::PARAM_STR);
$stmt->bindParam(3, $email, PDO::PARAM_STR);
$stmt->bindParam(4, $password, PDO::PARAM_STR);
$stmt->execute();
if ($stmt == true) {;?>
<link rel="stylesheet" type="text/css" href="style.css">
<div class="success-login">
<h2>Congratulations! You have been successfully registered</h2>
<p>You can go ahead and login now</p>
</div>
<?php } else {
echo "<script>alert('OOPPS! A problem has occcurred! Please try again!')</script>";
}
}
} else {
echo "Missmatched passwords";
}
} else {
echo "Please fill out all fields!";
}
}
?>