-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
86 lines (71 loc) · 3.11 KB
/
login.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
<?php
include_once "datosbd.php";
include_once "conexionbd.php";
include_once "funcionesVarias.php";
//var_dump($_POST);
$nombre_u = $_POST["nombre_u"];
$contrasenia = $_POST["contrasenia"];
//$nombre_u = "fulano";
//$contrasenia = "22222";
$datos_JSON = new \stdClass();
$datos_JSON->id_sesion=0;
$datos_JSON->id_usuario=0;
$datos_JSON->id_estado=0;
$datos_JSON->mensaje="";
?>
<?php
//1 - Búsqueda del usuario por su nombre
//$sqlLogin="SELECT * FROM usuario where nombre_u='".$nombre_u."'";
//1.1 - Creación de la conexión con la consulta correspondiente y obtención del resultado
//$resultado=consultaDB($sqlLogin);
//consultaDB($sqlLogin,$servidor,$usuario,$contraseña,$bdd);
//1.2 - Análisis del resultado de la consulta
// El resultado debe contener exactamente una (1) fila para que sea el deseado
// si hay menos de una fila, el usuario no existe, si hay más, el usuario aparece repetido
// indicando un error interno de la BdD y debe ser invalidado.
if(nombreUsuarioExiste($nombre_u)){
$registro = datosDelUsuario($nombre_u);
//1.3 - Obtención de datos de verificación: id de usuario y el hash
$id_usuario = $registro->id_usuario;
$hash = $registro->hash;
//1.4 - Verificación de la contraseña
if(password_verify($contrasenia,$hash)){
//1.5 - Obtención del ID de sesión
$id_sesion=iniciarSesion($id_usuario);
$id_estado = 0;
$mensaje="";
//1.6 - Generación de errores de estado a partir de datos de inicio de sesión
if($id_sesion->id == 0){
// Caso id_sesion = 0 -> No se pudo crear la sesión por errores del servidor,
// falla de conexión a MySQL o similares
$id_estado = 1;
$mensaje= $id_sesion->mensaje;
}
else{
$id_estado = 17;
$mensaje= "OK";
}
//1. - Pasaje de datos al objeto contenedor
$datos_JSON->id_sesion=$id_sesion->id;
$datos_JSON->id_usuario=$id_usuario;
$datos_JSON->id_estado=$id_estado;
$datos_JSON->mensaje=$mensaje;
}
//Error de constraseña
else{
$datos_JSON->id_sesion=0;
$datos_JSON->id_usuario=0;
$datos_JSON->id_estado=18;
$datos_JSON->mensaje="Nombre de Usuario o Contraseña incorrectos";
}
}
//2.0 - El usuario no se encuentra en la base de datos, por lo tanto no existe
else{
$datos_JSON->id_sesion=0;
$datos_JSON->id_usuario=0;
$datos_JSON->id_estado=18;
$datos_JSON->mensaje="Nombre de Usuario o Contraseña incorrectos";
}
$JSON_final = json_encode($datos_JSON);
echo $JSON_final;
?>