-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreg_check.php
More file actions
57 lines (45 loc) · 1.61 KB
/
Copy pathreg_check.php
File metadata and controls
57 lines (45 loc) · 1.61 KB
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
<?php
require_once('session_check.php');
require_once('WebServiceClient.php');
setError();
if (empty($_POST['username_p']) || empty($_POST['password_p'])) {
setError(ERR_GENERIC, "Username o password mancanti");
Redirect('reg.php');
}
$usr = trim($_POST['username_p']);
$pwd = $_POST['password_p'];
//ci sono simboli nell'username
if (preg_match(ALFANUM_REGEXP, $usr)) {
setError(ERR_GENERIC, htmlspecialchars("L'username contiene caratteri non validi, inserire solo lettere numeri e _"));
Redirect('reg.php');
}
//check lunghezza username
if (strlen($usr) > MAX_USN_LEN) {
setError(ERR_GENERIC, htmlspecialchars("L'username e troppo lungo, lunghezza max " . MAX_USN_LEN . " caratteri"));
Redirect('reg.php');
}
//check lunghezza pwd
if (strlen($pwd) > MAX_PWD_LEN) {
setError(ERR_GENERIC, htmlspecialchars("La password inserita e troppo lunga, lunghezza max " . MAX_PWD_LEN . " caratteri"));
Redirect('reg.php');
}
try {
//Richiamo il WS
$token = WebServiceClient::register($usr, $pwd);
if($token === null || $token === ""){
setError(ERR_LOGIN, "Registration failed");
Redirect('reg.php');
}
//istanzio la 'sessione' user
$_SESSION['token'] = $token;
$_SESSION['username'] = $usr;
setError();
}
catch (Exception $e) {
setError(ERR_LOGIN, "Registration failed: " . $e->getMessage());
Redirect('reg.php');
}
//Accesso effettuato
//Entro nella sezione riservata
Redirect('pers_temp.php');
?>