Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if(!$_POST['enviado']){
- //Generar el one time token y guardarlo en la sesion
- $token = rand();
- $_SESSION['login_token'] = $token;
- ?>
- <html>
- <head>
- <title>Secure Login</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <script type='text/javascript' src='libsha1.js'></script>
- <script lang="text/javascript">
- function generar_sha1(){
- var pass = document.getElementById('pass');
- var token = document.getElementById('token');
- pass.value = SHA1(pass.value+token.value);
- }
- </script>
- </head>
- <body>
- <h2>Secure Login</h2>
- <form method="post" onsubmit="return generar_sha1();">
- <table>
- <tr>
- <td width="80px">
- Username:
- </td>
- <td>
- <input type="text" name="usuario" />
- </td>
- </tr>
- <tr>
- <td>
- Password:
- </td>
- <td>
- <input type="password" id="pass" name="pass" />
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <input type="hidden" id="token" name="token" value="<?php echo $token ?>" />
- <input type="hidden" name="enviado" value="1" />
- <input type="submit" name="Ingresar" />
- </td>
- </tr>
- </form>
- </body>
- </html>
- <?php
- }else{
- //Usuario y Password del usuario
- $usuario = "usuario";
- $password = "1234";
- //Utilizar el one time hash enviado por el usuario contra el calculado para comprar
- if((sha1($password.$_SESSION['login_token']) == trim($_POST['pass'])) && $usuario == $_POST['usuario']){
- echo "El ingreso fue exitoso";
- }else{
- echo "Usuario o contrase?a incorrectos";
- }
- //Limpiar el one time token
- unset($_SESSION['login_token']);
- }
- ?>
Add Comment
Please, Sign In to add comment