-
Notifications
You must be signed in to change notification settings - Fork 0
/
signin.php
55 lines (52 loc) · 1.46 KB
/
signin.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
<?php
require_once("config/session.php");
require_once("config/database.php");
if ($_SESSION['username'])
{
header('Location: menber.php');
exit;
}
if (!empty($_POST))
{
$error = array();
if (empty($_POST['username']) || !preg_match('/^[a-z0-9]+$/', $_POST['username']) || !(strlen($_POST['username']) > 5))
{
$error['username'] = "vous n'avez pas entrer de pseudo valide, alphanumerique, plus de 5 caractère";
}
else
{
$req = $db->prepare('SELECT id FROM users WHERE username = ?');
$req->execute([htmlentities($_POST['username'])]);
$user = $req->fetch();
if ($user)
{
$error['username'] = "Cette pseudo est déjà pris";
}
}
if (empty($_POST['mail']) || !filter_var($_POST['mail'], FILTER_VALIDATE_EMAIL))
{
$error['mail'] = "Votre email n'est pas valide";
}
else
{
$req = $db->prepare('SELECT id FROM users WHERE email = ?');
$req->execute([htmlentities($_POST['mail']) ]);
$mail = $req->fetch();
if ($mail)
{
$error['mail'] = "Cette adresse mail est déjà prise";
}
}
$length = strlen($_POST['password']) >= 8;
$number = preg_match('#[0-9]#', $_POST['password']);
if (empty($_POST['password']) || !$length || !$number || $_POST['password'] != $_POST['repassword'])
{
$error['password'] = "Ce mot de passe est invalide, 8 caractère + 1 chiffe";
}
if (empty($error))
{
addUser($db, htmlentities($_POST['username']), htmlentities($_POST['mail']), htmlentities($_POST['password']));
}
}
require('views/view-index.php');
?>