-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsign_up.php
92 lines (83 loc) · 4 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
<?php
define('APPLICATION', true);
session_start();
require_once('php/class/Autoloader.php');
Autoloader::Register();
if(!Toolbox::IsConnected()) {
// Sign up tests
if(isset($_POST['submit'])) {
$message = new Message();
if(Toolbox::ArrayHasValue($_POST, ['username', 'email', 'password', 'confirm'])) {
$username = strip_tags($_POST['username']);
$email = strip_tags($_POST['email']);
$password = $_POST['password'];
$confirm = $_POST['confirm'];
if(strlen($username) <= 25 && strlen($username) >= 4) {
if(strlen($email) <= 254 && strlen($email) >= 6) {
if($password == $confirm) {
if(strlen($password) >= 4) {
$password = password_hash($password, PASSWORD_BCRYPT);
$db = new Database();
$res = $db->Execute('SELECT COUNT(*) as count FROM users WHERE username=? OR email=?', array($username, $email));
if($res->fetch(PDO::FETCH_OBJ)->count == 0) {
$db->Execute('INSERT INTO users (username, email, password) VALUES (?, ?, ?)', array($username, $email, $password));
Toolbox::Redirect('sign_in.php');
} else {
$message->SetError('This username or e-mail exists, choose another one');
}
} else {
$message->SetError('Your password is too short');
}
} else {
$message->SetError('Passwords do not match');
}
} else {
$message->SetError('The e-mail must have a minimum of 6 and a maximum of 254 characters');
}
} else {
$message->SetError('The username must have a minimum of 4 and a maximum of 25 characters');
}
} else {
$message->SetError('Fill all fields');
}
}
require_once('php/inc/header.inc.php');
if(isset($message)) {
$message->Show();
}
?>
<div class="container-fluid weighty-form">
<div class="row justify-content-md-center">
<div class="col-md-3">
<h1 class="text-center">Sign up</h1>
<form action="" method="POST">
<div class="form-group">
<input type="text" class="form-control" placeholder="Username" maxlength="25" name="username" value="<?php if(isset($_POST['username'])) echo $_POST['username']; ?>">
</div>
<div class="form-group">
<input type="email" id="inputSUEmail" class="form-control" maxlength="254" placeholder="E-mail" name="email" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>">
</div>
<div class="form-row">
<div class="form-group col-md-6">
<input type="password" class="form-control" placeholder="Password" name="password">
</div>
<div class="form-group col-md-6">
<input type="password" id="inputSUConfirm" class="form-control" placeholder="Confirm" name="confirm">
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary form-group-center" name="submit">Sign up</button>
</div>
</form>
<div class="text-center">
<a href="sign_in.php">Already registered ?</a>
</div>
</div>
</div>
</div>
<?php
require_once('php/inc/end.inc.php');
} else {
Toolbox::RedirectToHome();
}
?>