-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
131 lines (110 loc) · 4.66 KB
/
signup.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<html>
<head>
<title>Sign_Up</title>
<link rel = "stylesheet" href = "Styles\signup.css">
</head>
<body>
<h1> Welcome To Online Vehicle Parking System </h1>
<div class = "style2">
<form method = 'POST' action = "">
<h2> SignUp </h2>
<label for = 'username'> Username </label>
<input type = 'text' id = 'Username' name = 'username' autocomplete="off" required>
<br><br>
<label for = 'password'> Password </label>
<input type = 'password' id = 'Password' name = 'password' autocomplete="off" required>
<br><br>
<label for = 'phonenumber'> Phone Number </label>
<input type = 'text' id = 'phonenumber' name = 'phonenumber' autocomplete="off" required>
<br><br>
<input type = 'submit' class = 'signup' name = 'signup' value = 'SIGNUP'>
<br>
</form>
Already Have An Account! <a href = "index.php"> <button class = 'login'> LOGIN </button>
</div>
</body>
</html>
<?php
session_start();
if(isset($_POST['signup']))
{
$uname = $_POST['username'];
$upassword = $_POST['password'];
$phnnumber = $_POST['phonenumber'];
function validatePhoneNumber($phnnumber)
{
// Remove any non-numeric characters
$phnnumber = preg_replace('/[^0-9]/', '', $phnnumber);
// Check if the phone number is exactly 10 digits
if (strlen($phnnumber) == 10) {
return true; // Valid phone number
} else {
return false; // Invalid phone number
}
}
function validatePassword($upassword)
{
$errors = [];
// Minimum length requirement
if (strlen($upassword) < 8) {
$errors[] = "Password must be at least 8 characters long.";
}
// Check for at least one uppercase letter
if (!preg_match('/[A-Z]/', $upassword)) {
$errors[] = "Password must contain at least one uppercase letter.";
}
// Check for at least one lowercase letter
if (!preg_match('/[a-z]/', $upassword)) {
$errors[] = "Password must contain at least one lowercase letter.";
}
// Check for at least one digit
if (!preg_match('/\d/', $upassword)) {
$errors[] = "Password must contain at least one digit.";
}
// Check for at least one special character
if (!preg_match('/[^A-Za-z0-9]/', $upassword)) {
$errors[] = "Password must contain at least one special character.";
}
return $errors;
}
$passwordErrors = validatePassword($upassword);
if (validatePhoneNumber($phnnumber) && empty($passwordErrors))
{
// echo "Valid phone number: $phnnumber";
$con = mysqli_connect("localhost","root","","parkingsystem");
if(!$con)
{
die("Connection Failed".mysqli_connect_error(die));
}
$sql = "insert into users (username,password,phonenumber) values ('$uname','$upassword','$phnnumber')";
try
{
if(mysqli_query($con,$sql))
{
echo "<script> alert('User Successfully Created') </script>";
sleep(2);
echo"<script>window.location='slotbooking.php';</script>";
}
else
{
echo "<script> alert('Error in creating a User') </script>";
}
}
catch(Exception $e)
{
echo "<script>alert('Enter Username and Password to Register')</script>";
}
}
else
{
if (!validatePhoneNumber($phnnumber))
{
echo "<script>alert('Enter a valid phone number')</script>";
}
if (!empty($passwordErrors))
{
echo "<script>alert('Password is not valid. Errors: " . implode(", ", $passwordErrors) . "')</script>";
}
}
}
?>