Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
<%@ page import= "com.logicaalternativa.ejemplos.loginsha1.UtilCripto" %>
* index.jsp
* Copyright 2013 Miguel Rafael Esteban Martín <>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
// Se calcula la cadena aleatoria
String tokenSesion = "" + (
UtilCripto.obtenerNumeroAleatorio( 1, 9 ) * 1000000 +
+ UtilCripto.obtenerNumeroAleatorio( 0, 10 ) * UtilCripto.obtenerNumeroAleatorio( 0, 10000 )
// Se mete en sesión
session.setAttribute( "tokenSesion", tokenSesion );
<title>[] Ejemplo de securización acceso sha1</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" src=""></script>
<script language="JavaScript" src=""></script>
<script language="JavaScript" type="text/JavaScript">
function acceder(){
var contra = document.forms.formularioAcceso.contra.value + '';
var token= sha1('<%=tokenSesion%>' + contra);
document.forms.formularioAcceso.contra.value = '';
document.forms.formularioAcceso.token.value = token;
return true;
function sf(){
<body onLoad="javaScript:sf();">
<div align="center">
<p>[<b></b>] Ejemplo de securización acceso sha1</p>
<p>Para más información leé el <a href="">POST</a>. También puedes ver el <a href="" target="_blank">código</a></p>
<form name="formularioAcceso" method="post" action="resultado.jsp" onSubmit="return acceder()">
<input name="token" type="hidden" value="">
<table width="500" border="0" align="center" cellpadding="6" cellspacing="0">
<td><div align="right">Usuario:</div></td>
<td> <input name="usu" type="text" id="usu" value=""> </td>
<td><div align="right">Contrase&ntilde;a:</div></td>
<td><input name="contra" type="password" id="contra"></td>
<td colspan="2"><div align="center">
<input type="reset" name="Reset" value="Cancelar">
<input name="entrar" type="submit" id="entrar" value=" Entrar ">
<div align="center">
<p>Usuarios de prueba</p>
<table width="0" border="0" cellpadding="6" cellspacing="0">
<th><div align="right">Usuario</div></th>
<th><div align="left">Contraseña</div></th>
<td><div align="right">usu1</div></td>
<td><div align="left">contra1</div></td>
<td><div align="right">usu1</div></td>
<td><div align="left">contra2</div></td>