-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.php
221 lines (178 loc) · 6.17 KB
/
function.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
/*
Change line 186 & 187 by putting your email and password
*/
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
try
{
$bdd = new PDO('mysql:host=localhost;dbname=qyizbowl;charset=utf8', 'root', '0000');
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$url = implode('',array_slice(explode('/', $_SERVER['HTTP_REFERER']),1,2));
function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
{
$str = '';
$max = mb_strlen($keyspace, '8bit') - 1;
for ($i = 0; $i < $length; ++$i) {
$str .= $keyspace[random_int(0, $max)];
}
return $str;
}
if (isset($_POST['pseudo']) AND isset($_POST['email']) AND isset($_POST['pass']) AND isset($_POST['passconfirme']) AND isset($_POST['year']) AND isset($_POST['month']) AND isset($_POST['day']) AND isset($_POST['country']))
{
$email = htmlspecialchars($_POST['email']);
$pass = htmlspecialchars($_POST['pass']);
$pseudo = htmlspecialchars($_POST['pseudo']);
$passconfirme = htmlspecialchars($_POST['passconfirme']);
$year = htmlspecialchars($_POST['year']);
$month = htmlspecialchars($_POST['month']);
$day = htmlspecialchars($_POST['day']);
$birthdate = "$year-$month-$day";
$country = htmlspecialchars($_POST['country']);
$ip1 = "";
$ip2 = "";
$ip3 = "";
$ip4 = "";
$ip5 = "";
if (preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $pseudo) || preg_match('/\s/', $pseudo))
{
$ip1 = "Invalide Username";
}else if(strlen($pseudo)>30){
$ip1 = "Username too long";
}
function verify_email($email, $bdd)
{
$syntaxe='#^[a-zA-Z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#';
if(preg_match($syntaxe, $email)){
$reol = $bdd->prepare('SELECT id FROM members WHERE email = :email');
$reol->execute(array(
'email' => $email));
$singer = $reol->fetch();
if($singer){
return false;
}else{
$reol2 = $bdd->prepare('SELECT id FROM verifcation WHERE email = :email');
$reol2->execute(array(
'email' => $email));
$singer2 = $reol2->fetch();
if($singer2){
return false;
}else{
return true;
}
}
}
else{
return false;
}
}
if (!verify_email($email, $bdd)) {
$ip2 = "Invalide Email";
$mailv = false;
}else{
$mailv = true;
}
function verify_password($pass)
{
$syntaxe='#^[\sa-zA-Z0-9._-]{10,}$#';
$syntaxe1='#[A-Z]+#';
$syntaxe2='#[a-z]+#';
$syntaxe3='#[0-9]+#';
if(preg_match($syntaxe, $pass) AND preg_match($syntaxe1, $pass) AND preg_match($syntaxe2, $pass) AND preg_match($syntaxe3, $pass))
return true;
else
return false;
}
if (verify_password($pass) || strlen($pass)<10) {
if ( $passconfirme != $pass) {
$ip4 = "The Passwords are not Identical";
$ps = false;
}else{
$timeTarget = 0.05;
$cost = 8;
do {
$cost++;
$start = microtime(true);
password_hash("test", PASSWORD_BCRYPT, ["cost" => $cost]);
$end = microtime(true);
} while (($end - $start) < $timeTarget);
$passhash = password_hash("$pass", PASSWORD_BCRYPT, ['cost' => $cost]);
$ps = true;
}
}else{
$ip3 = "Invalide Password";
$ps = false;
}
$reponse = $bdd->query('SELECT * FROM members');
$more_than_one_pseudo = 0;
while ($donnees = $reponse->fetch())
{
if (strcmp($donnees['pseudo'], $pseudo) == 0 OR strlen($pseudo) == 0) {
$more_than_one_pseudo++;}
}
$reponse->closeCursor();
$reponse = $bdd->query('SELECT * FROM verifcation');
while ($donnees = $reponse->fetch())
{
if (strcmp($donnees['pseudo'], $pseudo) == 0 OR strlen($pseudo) == 0) {
$more_than_one_pseudo++;}
}
$reponse->closeCursor();
if ($more_than_one_pseudo != 0) {
$ip1 = "Used Username";
}
if ($mailv AND $ps AND $more_than_one_pseudo == 0)
{
$code = random_str(150);
$req = $bdd->prepare('INSERT INTO verifcation(pseudo, email, pass, birthdate, country, code) VALUES(:pseudo, :email, :pass, :birthdate, :country, :code)');
$req->execute(array(
'pseudo' => $pseudo,
'email' => $email,
'pass' => $passhash,
'birthdate' => $birthdate,
'country' => $country,
'code' => $code,
));
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'address';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('[email protected]', 'Board Cells');
$mail->addAddress($email, $pseudo);
$mail->isHTML(true);
$bodyContent = "<h1 style='text-align:center;'>Welcome, $pseudo</h1>";
$bodyContent .= "<p>Click in the following link to confirm your inscription http://".$url."/confirmation.php?token=$code&ps=$pseudo</p>";
$mail->Subject = 'Confirmation Email From Board';
$mail->Body = $bodyContent;
$mail->AltBody = "Go to the following link to confirm your inscription http://".$url"/confirmation.php?token=$code&ps=$pseudo";
$mail->send();
echo $pseudo.",pseudo";
} catch (Exception $e) {
$ip5 = "An Error had Occured. Please Retry.";
echo $ip1.",".$ip2.",".$ip3.",".$ip4.",".$ip5;
}
}
else{
echo $ip1.",".$ip2.",".$ip3.",".$ip4.",".$ip5;
}
}
?>