Showing posts with label How to Create Login Page with ASP. Show all posts
Showing posts with label How to Create Login Page with ASP. Show all posts

Create Login Page with ASP Connected to Database

<%
dim username, password, loginButton
username=TRIM(Request("username"))
password=TRIM(Request("password"))
logButton=Request("loginButton")="Login"
if logButton then
   Dim Con, sql, rec
   set Con = Server.CreateObject("ADODB.Connection")
   Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("database.mdb")
   'Select the record matching the username.
   sql = "SELECT * FROM tblusers WHERE UCase(username)='
"& UCase(username) & "' AND UCase(password)=' " & UCase(password) & " ' "
   set rec=Con.execute(sql)
   'If no match found, EOF is not true.
   if NOT rec.EOF then
      Response.Redirect("somepage.asp") 'Change to page redirect to after login
   else
      blankError="Invalid username." 'EOF is true, no match found.
   end if
end if
%>
<html>
<head>
<title>Login</title>
</head>
<body>
<form name="productForm" method="post" action="<%=Request.ServerVariables("URL")%>">
<center>
<table border =1>
<tr><td colspan="2">
<%

if blankError<>"" then
Response.Write("<center><font color='red' size='3'>"&blankError&"</font></center>")
end if
%>
</td></tr>
<tr>
<td><Strong><font face="courier new" size="3">Username:</font></strong></td>
<td><input type="text" name="username" size="35"></td>
</tr>
<tr>
<td><Strong><font face="courier new" size="3">Password</font></strong></td>
<td><input type="password" name="password" size="35"></td>
</tr>
<tr><td colspan="2" align="center"><input type="submit" name="loginButton" value="Login">
<input type="reset" name="reset" value="Clear"></td>
</tr>
</table>
</center>
</form>
</body>
</html>