Google
Useful Links: ____ Article Search -___ Link Parters ___- Ebook Library___- Product Search

place1holder

.
New Articles
Ebook Library
Link Exchange
Advertising Space
Computer Directory
Join Our Newsletter

Name:
Email:


You will recieve a weekly email that contains new articles, useful product recommendations & more! [Privacy]



place2holder



Further
Reading ...
Increase website traffic and be succesfull online.
For your website to be successful, you need to understand exactly how more content brings more visitors to your site as well as how to generate quality content that is related to your particular website theme. All webmasters want lots of it and need...

Your Affiliate Web Site Is Built – Now What?
When I first got my web site built, I thought I finally I had a presence on-line. Wrong! I soon found out that I needed someone to host my site, and I needed a domain name. This, I found, was my moment of utter confusion. And my first thought...

10 Awesome Ways To Attract More Orders
10 Awesome Ways To Attract More Orders by: William R. Nabaza of http://www.Nabaza.com 1. Create a free e-book directory on a specific topic at your web site. People will visit your web site to read the free e-books and may see your product...

Build Your Own Computer
Build Your Own Computer If I cand do it so can you Written by: George W. Cannata I’m eighty-one years old and I bought my first computer six years ago. When I bought it I hardly knew how to turn it on. I consider myself still a Newbie as I’ve...


 

Logging In Using ASP - Access2000




Written By:
Amrit Hallan

After receiving a few queries about how to store passwords using
ACCESS and ASP, and then use them as "logins", I thought, well,
why not write in a separate article, instead of attaching
multiple ASP files that are full of confusing comments and
variables only to be decipherable by my brain?

I'm assuming you've installed, and are running PWS (Personal Web
Server) on your machine, if you are not already working on a
server that supports ASP.

First of all, create a database, for instance, customers.Define a
table with all the fields you require (include email and
password).

After the database has been created, you need to create a DNS in
order to access this database through your ASP pages.

If you have never created it, this is how you do it:

Go to the Control Panel (My Computer -> Control Panel), and click
on the icon that should be saying "ODBC Data Sources (32bit)". In
the resulting window, select the "System DSN" tab. Then click on
the "Add..." button. From the given list of Database drivers,
select "Microsoft Access Driver (*.mdb)" and click the "Finish"
button. You reach a place where you have to enter the "Data
Source Name". Enter it, anything, for instance, "customers". Then
click the "Select..." button. This lets you select the Access
database you created. Press Ok, press Ok, and press Ok. Your DSN
is created.

In the first part, I'll write about storing the passwords.

Before this, let's make an include file to create and initialize
the session variables that we are going to need (we can use
cookies, but some clever folks disable cookies on their
browsers).

File name: sessions.inc

<%

if session("email")="" then
session("email")="notlogged"
session("pass")=""
end if

%>

This file you can include in every page as



so that you can use them whenever you need them.

Now accepting login and password.

For this you require a normal HTML form. You can have "n" number
of fields in a form, but here, our primary concern is, getting
the email as login, and the accompanying password.

Here's the form:

Please enter your details:



onsubmit="return validate(this);">
Enter Email:

Enter Password:




We validate the form before it proceeds to the "action" file so
that there is very little server-side processing. A simple
validation:

Note: Put the following Javascript above the tag.



So now when the user clicks on "Submit", he/she goes to
"storelog.asp" In between, you can have a file to confirm the
form fields and give the user an option to modify them before
finally saving.

A few things. In order to use a database through ASP, you need to
have a DNS created for that database on the server.

STORELOG.ASP should somewhat look like - continued below ...





continued ...
this:

<%
dim sEmail, sPass, noError
noError="y"
sEmail=request.form("email")
sPass=request.form("pass")

' The following lines setup a connection to the DNS we created
above

Dim toDatabase 'To connect to the DNS
Dim toRecordset 'To connect to the individual tables

Set toDatabase = Server.CreateObject("ADODB.Connection")
toDatabase.Open "customers"

Set toRecordset = Server.CreateObject("ADODB.Recordset")
toRecordset.Open "logins", toDatabase, 2

' 2 = Opens the recordset in "Write Mode"

' Let us say "logins" is some table you created in the database.

toRecordset.AddNew
toRecordset("email")=sEmail
toRecordset("password")=sPass
on error resume next
toRecordset.Update
if err.number<>0 then
' do something if some error occurs.
' one error could be that the email already exists in the
database.
noError="n"
end if

toRecordset.Close

Set toRecordset = Nothing

toDatabase.Close

Set toDatabase = Nothing

if noError="y" then
' If the info was saved smoothly.

session("email")=sEmail
session("pass")=sPass
end if

' Here you can display some message that the record has been
saved.
%>

This saves the login information of a new customer. Now, how do
we use it in the future? First, the login form, that could be on
any page.

Remember you can use somewhat same validation Javascript here
too, so I'm not repeating it, but just mentioning it.

Please login by entering your email and password.



onsubmit="return validate(this);">
Enter Email:

Enter Password:




LOGIN.ASP

At the top of the page, along with other ASP commands, include
this too:

<% response.buffer=true %>

This is required if you want to send the user to some page after
he/she has successfully logged in.

<%

dim sEmail, sPass, noError
noError="y"
sEmail=request.form("email")
sPass=request.form("pass")

' The following lines setup a connection to the DNS we created
above

Dim toDatabase 'To connect to the DNS
Dim toRecordset 'To connect to the individual tables

Set toDatabase = Server.CreateObject("ADODB.Connection")
toDatabase.Open "customers"

fndSQL="select * from logins where email='" & sEmail & "' and
password='" & sPass & "'"

Set toRecordset=toDatabase.execute(fndSQL)

if toRecordset.eof then

response.write "Your details are not in the database, please
try again, or register yourself."

else

session("email")=toRecordset("email")
session("pass")=toRecordset("password")

end if

toRecordset.Close

Set toRecordset = Nothing

toDatabase.Close

Set toDatabase = Nothing

response.redirect "To some URL"

%>

>From now onwards, whenever you want to perform some action that
should only be performed if the user is logged in, just check the
value is session("email"), like:

<%

if session("email")<>"notlogged" then

' do things for the logged in customer

else

' tell the customer that he she is not logged in.

end if

%>

Hope this helps. If you need further queries, or in future you
need some other ASP work, you are welcome to write to me at
amrit@bytesworth.com.

About the Author

Amrit Hallan is a freelance web designer. For all web site
development and web promotion needs, you can get in touch with
him at http://www.bytesworth.com. For more such articles,
visit http://www.bytesworth.com/articles and
http://www.bytesworth.com/learn You can subscribe to his
newsletter [BYTESWORTH REACHOUT] on Web Designing Tips & Tricks
by sending a blank email at bytesworth-subscribe@topica.com



_Additional Resources ...









Bookmark Managers: Programs vs. Web Services
The rapid development of the World Wide Web in recent years has led to an explosive growth of information on the Internet. Our contemporary lifestyle would be unimaginable without access to such a super-abundant cornucopia of valuable information...

Valuable Tips for Catalog Printing
Basic knowledge is a vital factor to save you money and avoid delays in your printing needs. So to give you this familiarity with basic information and to keep you away from printing dilemmas, here are some valuable tips that you should...

An Embarrassment of Riches - Part II
http://www.doi.org/ The DOI Foundation has unveiled the DOI-EB (EB stands for e-books) Initiative in the Book Expo America Show 2001, to, in their words: "Determine requirements with respect to the application of unique...



This website is powered by Hostland ...