-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsign-up.php
166 lines (133 loc) · 6.66 KB
/
sign-up.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html>
<head>
<link rel="apple-touch-icon" sizes="150x150" href="icons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="icons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="icons/favicon-16x16.png">
<link rel="stylesheet" href="css/forms.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<meta content="width=device-width, initial-scale=1.0" charset="UTF-8" name="viewport"/>
<title>Sign Up</title>
</head>
<body>
<a href="index.php" class="logo">
<h1 class="logo">koliTECH</h1>
</a>
<div class="form-div">
<form action="" class="sign-up-form" method="post">
<!--First Name -->
<div class="col-2">
<input type="text" class="fName" id="txtFirstname" name="txtFirstname" placeholder="First Name" required>
</div>
<!--Last Name -->
<div class="col-2">
<input type="text" class="Name" id="txtLastame" name="txtLastname" placeholder="Last Name" required>
</div>
<!--Email -->
<div class="col-2">
<input type="email" class="email" id="txtEmail" name="txtEmail" placeholder="[email protected]" required>
</div>
<!--Password -->
<div class="col-2">
<input type="password" class="password" id="password" name="password" placeholder="Password" required>
</div>
<!--Confirm Password -->
<div class="col-2">
<input type="password" class="password2" id="password2" name="password2" placeholder="Confirm Password" required>
</div>
<div id="match-div">
<p id="match" > </p>
</div>
<!--Buttons -->
<input type="submit" class="submitbtn" id="submitbtn" name="Submit" value="SIGN UP">
<input type="reset" class="resetbtn" id="resetbtn" name="Reset" VALUE="CLEAR">
</form>
</div>
<div class="error-message">
<?php
ob_start();
$error = NULL;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\PHPMailer;
if(isset($_POST['Submit'])){
require('config.php');
//Get form data
$Fname = $_POST['txtFirstname'];
$Lname = $_POST['txtLastname'];
$Email = $_POST['txtEmail'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$r_email = '/^[^0-9][_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';
$sql_email = "SELECT * FROM accounts WHERE Email = '$Email' LIMIT 1";
$res_email = mysqli_query($conn,$sql_email);
if (strlen($password != $password2)){
//password compare
$error = "<p class='php-match'>Passwords do not match</p>";
}
// else when the passwords matched but...
elseif (strlen($password) < 8){
$error = 'Password too short';
}
elseif (!preg_match("#[0-9]+#",$password)){
$error = 'Must include a number';
}
elseif (!preg_match("#[A-Za-z]+#",$password)){
$error = 'Must include a letter';
}
elseif (mysqli_num_rows($res_email) > 0){
// check if email already exists
$error = 'Email already existing';
}
elseif (!preg_match($r_email,$Email)){
$error = 'Invalid email address';
}
else{
require('config.php');
// sanitize the data
$Fname = mysqli_real_escape_string($conn,$Fname);
$Lname = mysqli_real_escape_string($conn,$Lname);
$Email = mysqli_real_escape_string($conn,$Email);
$password = mysqli_real_escape_string($conn,$password);
$password2 = mysqli_real_escape_string($conn,$password2);
$gender = mysqli_real_escape_string($conn,$gender);
//generate hash
$hash = md5(time().$Email);
//insert account into database
$password =md5($password);
$insert = mysqli_query($conn, "INSERT INTO accounts(Fname,Lname,Email,Password,hash)VALUES('$Fname','$Lname','$Email','$password','$hash')");
if ($insert)
{
//send email to user in order to verify account
require 'vendor/PHPMailer/src/Exception.php';
require 'vendor/PHPMailer/src/PHPMailer.php';
require 'vendor/PHPMailer/src/SMTP.php';
$mail = new PHPMailer();
$mail = new PHPMailer(true);
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host ='smtp.gmail.com';
$mail->SMTPAuth = 'true';
$mail->Username = '[email protected]';
$mail->Password = 'gJlYCO%AE*iN1hEp7a)W';
$mail->SMTPSecure =PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom('[email protected]','Kolitech');
$mail->addAddress($Email,$Fname);
$mail->isHTML(true);
$mail->Subject = 'Verification Email';
$mail->Body = "
<a href='http://localhost/kolitech/verify.php?hash=$hash'>Register Account</a>";
$mail->send();
header("location: Submitted.php");
}
}
}
echo '<p class="error">'.$error.'</p>';
?>
</div>
<div class="alt">
<p class="account-already">Already have an account? <a href="sign-in.php" class="account-already">Sign in</a></p>
</div>
</body>
<script rel="script" src="Script.js"><script>
</html>