-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
87 lines (68 loc) · 2.57 KB
/
index.php
File metadata and controls
87 lines (68 loc) · 2.57 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<!-- css -->
<link rel="stylesheet" href="./index.css">
<title>Document</title>
</head>
<body>
<div class="videoContainer">
<video class="backgroundVideo" muted autoplay loop src="./public/assets/background3.mp4"></video>
</div>
<?php
session_start();
$message = '';
$autenticado = false;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['usuario']) && isset($_POST['contrasena'])) {
$usuario = trim(htmlspecialchars($_POST['usuario']));
$contrasena = trim(htmlspecialchars($_POST['contrasena']));
$jsonFile = 'usuarios.json';
if (file_exists($jsonFile)) {
$jsonData = file_get_contents($jsonFile);
$usuarios = json_decode($jsonData, true);
foreach ($usuarios as $user) {
if ($user['usuario'] === $usuario && $user['contrasena'] === $contrasena) {
$autenticado = true;
$_SESSION['user'] = $user;
$_SESSION['autenticado'] = $autenticado;
header("Location: cajero.php");
exit;
}
}
$message = $autenticado ? 'Usuario autenticado' : 'Usuario o contraseña incorrectos';
} else {
$message = 'El archivo de usuarios no existe.';
}
} else {
$message = 'Por favor, complete todos los campos.';
}
}
?>
<div class="containerLogin">
<div class="containerLogin-title">
<img class="container-title_iconBank" src="./public/assets/banco.png" alt="icono de banco">
<h1>Cajero Automático</h1>
</div>
<div class="containerLogin-form">
<h1>Iniciar Sesión</h1>
<div class="containerLogin-form_formAction">
<form action="" method="POST">
<input type="text" placeholder="Usuario" class="form-control mb-5 color-white" id="usuario" name="usuario" required>
<input type="password" placeholder="Contraseña" class="form-control" id="contrasena" name="contrasena" required>
<button type="submit" class="btn btn-primary mt-4">Ingresar</button>
</form>
<?php if (!empty($message)): ?>
<div class="mt-3 alert <?php echo $autenticado ? 'alert-success' : 'alert-danger'; ?>">
<?php echo $message; ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
</body>
</html>