Guest User

Untitled

a guest
Jun 24th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.66 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. if(!$_POST['enviado']){
  6.  
  7.     //Generar el one time token y guardarlo en la sesion
  8.     $token =  rand();
  9.     $_SESSION['login_token'] = $token;
  10.  
  11.     ?>
  12.     <html>
  13.     <head>
  14.         <title>Secure Login</title>
  15.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  16.         <script type='text/javascript' src='libsha1.js'></script>
  17.         <script lang="text/javascript">
  18.             function generar_sha1(){
  19.                 var pass = document.getElementById('pass');
  20.                 var token = document.getElementById('token');
  21.                 pass.value = SHA1(pass.value+token.value);
  22.             }
  23.         </script>
  24.     </head>
  25.     <body>
  26.         <h2>Secure Login</h2>
  27.         <form method="post" onsubmit="return generar_sha1();">
  28.         <table>
  29.             <tr>
  30.                 <td width="80px">
  31.                     Username:
  32.                 </td>
  33.                 <td>
  34.                     <input type="text" name="usuario" />
  35.                 </td>
  36.             </tr>
  37.             <tr>
  38.                 <td>
  39.                     Password:
  40.                 </td>
  41.                 <td>
  42.                     <input type="password" id="pass" name="pass" />
  43.                 </td>
  44.             </tr>
  45.             <tr>
  46.                 <td colspan="2">
  47.                     <input type="hidden" id="token" name="token" value="<?php echo $token ?>" />
  48.                     <input type="hidden" name="enviado" value="1" />
  49.                     <input type="submit" name="Ingresar" />
  50.                 </td>
  51.             </tr>
  52.         </form>
  53.     </body>
  54.     </html>
  55.     <?php
  56. }else{
  57.    
  58.     //Usuario y Password del usuario
  59.     $usuario = "usuario";
  60.     $password = "1234";
  61.    
  62.     //Utilizar el one time hash enviado por el usuario contra el calculado para comprar
  63.     if((sha1($password.$_SESSION['login_token']) == trim($_POST['pass'])) && $usuario == $_POST['usuario']){
  64.         echo "El ingreso fue exitoso";
  65.     }else{
  66.         echo "Usuario o contrase?a incorrectos";
  67.     }
  68.    
  69.     //Limpiar el one time token
  70.     unset($_SESSION['login_token']);
  71. }
  72.  
  73. ?>
Add Comment
Please, Sign In to add comment