-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerarToken.php
27 lines (27 loc) · 1.25 KB
/
generarToken.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
<?php
include("myconnection.php");
if(!empty($_POST['usuario']) && !empty($_POST['clave'])) { // GENERAR TOKEN
$time_pre = microtime(true);
$user = $_POST['usuario']; // usuario
$pass = hash('sha256', $_POST['usuario'] . $_POST['clave']); // clave
$token = hash('sha256', $_POST['usuario'] . $_POST['clave'] . date('Y-m-d H:i:s')); // token generado
$sql = "SELECT * FROM usuario WHERE usuario = '".$user."' AND clave = '".$pass."'";
$ejecucionSQL = $conexion->prepare($sql);
$ejecucionSQL->execute();
$res = $ejecucionSQL->fetchAll();
$count = $ejecucionSQL->rowCount();
foreach ($res as $rs) {
if ($count > 0) {
$sql = "UPDATE `transporte`.`usuario` SET `token` = '".$token."' WHERE `id` = '".$rs['id']."';";
$ejecucionSQL = $conexion->prepare($sql);
$ejecucionSQL->execute();
echo $token;
}
}
$time_post = microtime(true);
$time = $time_post - $time_pre;
$time = $time*pow(10,3);
$sql = "INSERT INTO `transporte`.`auditoria` (`fecha_acceso`, `user`, `response_time`, `endpoint`) VALUES ('" . date('Y-m-d H:i:s') . "', '" . $user . "', '" . $time . "', 'generarToken');";
$ejecucionSQL = $conexion->prepare($sql);
$ejecucionSQL->execute();
}