Free web development scripts for the webmasterDevelopment Scripts


 social media marketing services
 Site Navigation
Clicky Web Analytics
 o Development Scripts
 o Text Only Edition
 o PHP.net News
 o Tutorials
 o Register an account
 o New entries this week
 o Affiliates/Links
 o Contact Us
 o About us
 o Advanced Search

 Browse Path
 o 1 user online
 o Most users online: 67
 o Home
  o ASP
   o Cookies/Sessions
    o Script

 Member Login
User Name
Password

 Standards
Valid XHTML 1.0!
Valid 
CSS!

 Recommended Links
 o PHP Freaks
 o Paper Free Invoicing
 o Tutorials
 o Expired Domain Crawler

Validate logins with ASP, MS Access and Cookies (Rated 0)

Description:

Having a user login on your page is arguably the best and easiest way for validation purposes leading into "members-only" or administration pages. This script will validate form input against field in a database. The script will connect to the database and query the database fields - if the form input matches the database, a cookie will be allocated which will remain across any further ASP pages, until destroyed. Page views of admin or member pages can then be validated by checking for the cookie, if the cookie is found, the user can continue and if the cookie is not found, the user is redirected back to the login screen.

Requirements: ASP running on IIS4.0, 5.0 or Apache under Chilisoft ASP. Microsoft Access database with username and password fields. Some data input into the database for 1 or more valid users to login with.

The script consists of 3 pages, the form to enter the login details, the page the login details are posted to and processed with, and the connectionstring which is included on any page which connects to the database.

The script can be expanded upon by using the last piece of code, for validating the cookie value. This can be placed on all member pages and will disallow access and redirect back to the login form if the cookie isnt present.

Code starts here


Firstly, create the form with username and password text fields. (form.html)



<html>
<head>
<title>validate usernames and passwords with ASP, MS Access and cookies</title>
<body>
<form name="myform" action="vdateUsr.asp" method="post">
Username:<br />
<input name="username" type="text" size="20" maxlength="20" /><br />

Password:<br />
<input name="password" type="password" size="20" maxlength="20" /><br />
<input name="submit" type="submit" />
</form>
</body>
</html>

Create the ASP page which will connect to the database and validate the input. (vdateUsr.asp)


<%@Language=VBScript%>

<%
Option Explicit
%>

<!-- METADATA TYPE="typelib"
FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<!-- #include file="Connectionstring.asp" -->


<%
' /////////////////////////////////////
' login validation script
' Matt Millross
' www.designplace.org
' free for use as long as copyright notice left intact
' For more scripts, visit www.designplace.org
' /////////////////////////////////////

' variables
dim cnStr
dim rcSet
dim frmUsername
dim frmPassword
dim sqlStr

'store form input into variables
frmUsername = Request.Form("username")
frmPassword = Request.Form("password")

'create connection and recordset objects
Set cnStr = Server.CreateObject("ADODB.Connection")
Set rcSet = Server.CreateObject("ADODB.Recordset")

' defining database connection (connectionstring.asp)
cnStr.ConnectionString = path
cnStr.Provider = provider
cnStr.open

' execute sql and open as recordset
sqlStr = "Select * From authorised_user_table where username = '" _
& Request.Form("username") & "' and password = '" & Request.Form("password") & "'"

' Opens the returned values from the SQL as a recordset, ready for iteration by ASP
set rcSet = cnStr.Execute(sqlStr)

' validate variables against database
If (not rcSet.BOF) and (not rcSet.EOF) then
response.cookies("validated_user") = frmUsername
response.write "<h1>Login successful!</h1>"
response.write "<p>Welcome " & rcSet.fields(1) & "</p>"
else
response.write "incorrect username and/or password"
end if
%>



Create connection string for use on any page which needs a database connection. (connectionstring.asp)


<%
' connection string

dim path
dim provider

' change this path to your database path
path = "c:\path\to\yourdatabase.mdb"
provider = "Microsoft.Jet.OLEDB.4.0"

%>


<%
' place this code on pages you want to validate for a user login

if request.cookies("validated_user") = "" then
response.redirect("form.html")
end if

%>
*Note: To remove the cookie value used across all pages within the application, use request.cookies("validated_user") = ""


Submitted by Devscripts on 13-02-2003 20:06


Recent Additions (from all categories)

(PHP) T Shirt Printing Software

(PHP) Youtube Video Organizer Script

(PHP) MP3z - MP3 Search Engine Script

(PHP) Recipez- PHP Recipe Script

(ASP) Stop image hotlinking and downloading. Web image protection is easy with Image Trapper.

Top Rated Scripts

(Javascripts) Javascript Delayed Redirection Rating: 5

(PHP) Random Links and images with PHP & MySQL Rating: 5

(PHP) RSS/XML news feed headline grabber! Rating: 5

(PHP) Random Signatures/Avatars Rating: 5

(Javascripts) Detecting Client Web Browser Rating: 5

© Copyright 2003 - Devscripts.net  Web Analytics