ARCHIVO login.asp
La consulta es a una base de datos SQL server "X", con nombre de tabla "tabla_users" con campos "users" y "password".
Para la consulta a la Base de Datos utilizo ADO.
************************************************************************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>:: Bienvenido a SYPRIS TECHNOLOGIES ::</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
text-decoration: none;
color: #000000;
}
a:visited {
text-decoration: none;
color: #000000;
}
a:hover {
text-decoration: none;
color: #000000;
}
a:active {
text-decoration: none;
color: #000000;
}
.Estilo1 {font-family: Verdana, Arial, Helvetica, sans-serif}
.Estilo4 {color: #666699}
.Estilo6 {font-size: x-small}
.Estilo7 {
font-size: large;
color: #666699;
font-style: italic;
}
.Estilo8 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: x-small;
color: #666699;
}
.Estilo9 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: x-small;
font-weight: bold;
color: #666699;
}
-->
</style></head>
<body bgproperties="fixed">
<table width="250" border="1" cellspacing="2" align="center">
<tr>
<td>
<table width="800" border="0" align="center" cellspacing="0">
<tr>
<td bgcolor="#ffffff"><div align="center"></div></td>
</tr>
<tr>
<td bgcolor="#ffffff">
<DIV align=right><hr align="center">
</DIV></td>
</tr>
</table>
<table width="802" border="0" align="center" cellspacing="10" bgcolor="#ffffff">
<tr>
<td height="618" align="middle" valign="top"><p align=right><FONT face=Verdana color=black
size=2><STRONG></STRONG></FONT></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<%
'Para los redireccionamientos
Response.Buffer=True
Dim conexion, rs, SQL, user, password
'Recogemos el formulario
user=Trim( Request.Form("user") )
password=Trim( Request.Form("password") )
'Si no lo ha enviado, es decir no hay nada en estas variables
'le presentamos el formulario
if user="" then
MostrarFormulario
else
'Validamos su identidad
set conexion=Server.CreateObject("ADODB.Connection")
conexion.Open "DRIVER={SQL Server};server=toluca113.sypris.com;uid=usuario; pwd=contraseña; database=nombredetubasededatos"
SQL="SELECT * FROM tabla_users WHERE (users='"&user&"' AND password='"&password&"');"
Set rs=Server.CreateObject("ADODB.Recordset")
'Ejecutamos consulta
rs.Open SQL,conexion,1
if (rs.BOF or rs.EOF) then
'No existe ese usuario con esa contraseña
'Así que le negamos el acceso
Session("aut")=False
Response.Write("Lo siento, no existe ese usuario/contraseña.")
%>
<meta http-equiv="refresh" content="3;URL=login.asp">
<%
else
'Iniciamos sesion del usuario y mandamos a la pagina de bienvenida
Session("user")=user
Session("aut")=True
Response.Redirect("options.asp") ' A esta pagina la redirecciona
end if
end if
'Subprograma MostrarFormulario
Sub MostrarFormulario
%>
<table width="200" border="1" cellspacing="5">
<tr>
<td>
<table width="200" border="0" cellspacing="5">
<tr>
<td width="50%" class="Estilo9">User</td>
<td>
<FORM METHOD="post" ACTION="login.asp">
<INPUT NAME="user"
></td>
</tr>
<tr>
<td width="50%" class="Estilo9">Password</td>
<td><INPUT TYPE="password" NAME="password"></td>
</tr>
<tr>
<td colspan="2"><center><INPUT TYPE="submit" VALUE="ENTRAR" class="Estilo9"></center></FORM></td>
</tr>
</table></td>
</tr>
</table>
<%
End Sub
%>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<hr align="center">
<div align="center" class="Estilo9">:: Mi empresa.com :: </div></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
*************************************************************************************
Fin de Archivo login.asp
Si tienes alguna duda
[email protected]