Log In System (Updated code)
by Vipin Sharma 


This code is for bignners
I've used two files for checking user name and password from the database.
1.default.asp (ask for username & password)
2.check_user.asp
Database Section
In database first we make a table called "users"
fields datatype
uid text
pwd text

'**********default.asp**************
<head> 
<title> Check User::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::</title> 
<script language="javascript"> 
function check_fields() 
{
if (document.main_form.uid.value =="")
{
alert("Please Enter The User Name");
document.main_form.uid.focus();
return(false);
}
if (document.main_form.pwd.value =="")
{
alert("Please Enter The Password");
document.main_form.pwd.focus();
return(false);
}
document.main_form.submit ();
return(true);
}
function help_file(){
window.open ("help.asp","HELP","width=550,height=350,status=no,toolbar=no,menubar=no");
}
function loads(){
document.main_form.uid.focus();
}
</script> 
</head> 
<body onLoad="loads()"> 

<p align="center"> <b> <font size="3"> DisbursementTracking System<br> 
</font> 
<font size="1"> Version2.0</font> </b> 
<br> 
<br> 
<div align="center"> 
<center> 
<table border="0" width="93%" cellspacing="3" cellpadding="5" bgcolor="#0099CC"> 
<tr> 
<td width="50%" bgcolor="#336699"> <br> 
</center> 
<form method="POST" action="check_user.asp" name=main_form> 
<div align="center"> 
<table border="0" width="84%" background="images/tdback.gif" height="169" cellspacing="1" cellpadding="3"> 
<tr> 
<td width="100%" height="16" colspan="2" bgcolor="#009868"> 
<p align="left"> <b> <font size="2"> Login! 
<img border="0" src="images/help.gif" onclick=help_file(); alt="Click Here For Help.:::::::::::;"> </font> </b> </td> 
</tr> 
</center> 
<center> 
<tr> 
<td width="50%" height="23" align="right" valign="middle"> Username:</td> 
<td width="50%" height="23"> <input type="text" name="uid" size="16"> </td> 
</tr> 
<tr> 
<td width="50%" height="37" align="right" valign="middle"> Password:</td> 
<td width="50%" height="37" valign="middle"> <input type="password" name="pwd" size="13"> </td> 
</tr> 
</center> 
<tr> 
<td width="50%" height="38"> 
<p align="right"> <input type="button" value="Login" onclick = check_fields() name="B1" style="font-family: Verdana; font-size: 8pt; color: #003498"> </td> 
<center> 
<td width="50%" height="38"> <input type="reset" value="Reset" name="B2" style="font-family: Verdana; font-size: 8pt; color: #000080"> </td> 
</tr> 
</table> 
</center> 
</div> 
</form> 
</center> 
</td> 
<td width="50%" valign="top" bgcolor="#336699"> <font color="#FFFFFF"> <b> <font size="3"> 
<b> Please Log in</b> </font> 
<ul> 
<li> <font color="#FFFFFF"> To Log in to the application portal type
uer name & password in the boxes at left.</font> </li> 
<li> <font color="#FFFFFF"> Click the Log In Button to log in.</font> </li> 
<li> <font color="#FFFFFF"> Click Reset to clear the text boxes.</font> </li> 
</ul> 
<p> <font color="#FFFFFF"> If you do not know your login information ,please 
contact your help desk or system administrator.<b> <br> 
</b> <br> 
</font> </p> 
</td> 
</tr> 
</table> 
</div> 
<p align="center"> 
<br> 
</body> 
'****************end of file****************

'****************check_user.asp************
<% 

set objcon=server.CreateObject ("adodb.connection")
dim constr
'you can use dsn method/2nd method
constr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db/db.mdb")
'constr ="dsn=dts"
objcon.Open constr
set objrs=server.CreateObject ("adodb.recordset")
objrs.Open "select * from users where (uid='"&Request.form ("uid")&"' and pwd='"&Request.form ("pwd")&"')",objcon,1,2
if objrs.EOF and objrs.BOF then
%> 
<script language="javascript"> 
alert("Sorry You are Not Authorsied User");
</script> 
<%
Response.Write ("<a href=default.asp> GO Back For Login!</a> ")
else
Response.Write ("yourmainpage.asp ")
end if

%> 
'*******************end of file************* 

