Go4Expert

Go4Expert (http://www.go4expert.com/)
-   ASP (http://www.go4expert.com/articles/asp-tutorials/)
-   -   Simple Login in ASP using MS Access database (http://www.go4expert.com/articles/simple-login-asp-using-ms-access-t1237/)

shabbir 19Aug2006 10:54

Simple Login in ASP using MS Access database
 
Create a database in MSAccess and save database as Studentrecords.mdb. Now add a table to the database using the following format
Code:

StudentNO  Text
FName      Text
SurName    Text
Password  Text

Save the table as tblStudent.

Now create a new file and name it login.asp
Code: ASP

<html>

<head>
<title>Home</title>
</head>
<body bgcolor="#003366">
<center>
<%
'StudentNo Of Logged in user
Dim Username
'
Retrieving Username
Username=Request.QueryString("username")
'Invalid Username password
if UserName <> "" then
    Response.Write "<font color='
#FFAA00'>"
    Response.Write "<font face='
Verdana' size=2>"
    Response.Write"Invalid UserName Password. Please Re-login"
    Response.Write "</font></font>"
end if
%>
  <form method="POST" action="verify.asp">
  <table border="1" cellspacing="1" bordercolor="#111111" id="AutoNumber1" height="82">
    <tr>
      <td height="23"><font color="#FFFFFF" face="Verdana" size="2">Student Number</font></td>
      <td width="148" height="23">
        <p align="center">
        <font face="Verdana" color="#FFFFFF">
        <input type="text" name="username" size="20" value=""><font size="2">
        </font></font>
      </td>
    </tr>
    <tr>
      <td height="22"><font color="#FFFFFF" face="Verdana" size="2">Password</font></td>
      <td width="148" height="22">
      <p align="center"><font color="#FFFFFF" face="Verdana"><input type="password" name="password" size="20"></font></td>
    </tr>
    <tr>
      <td width="210" colspan="2" height="22">
      <p align="center"><font face="Verdana"><font color="#FFFFFF">
      <input type="checkbox" name="rememberme" value="ON"></font><font size="2" color="#FFFFFF">Remember
      Me</font></font></td>
    </tr>
    <tr>
      <td width="210" colspan="2" height="22">
      <p align="center"><font face="Verdana" color="#FFFFFF"><input type="submit" value="LogIn" name="B1"><font size="2">&nbsp;</font><input type="button" value="New User" name="B2" onClick = "location.href('
signup.asp');"></font></td>
    </tr>
  </table>
  </form>
  </center>
</div>
</body>
</html>

Now create another file and name it verify.asp
Code: ASP

<body bgcolor="#003366">
<%

'Connection String
Dim Conn
'
Query to be executed
Dim SQLQuery
'Recordset
Dim rs
'
StudentNo Of Logged in user
Dim UserName
'Password of User
Dim Password

'
Getting information from submitted form
UserName = request.form("username")
Password = request.form("password")
RememberMe = request.form("rememberme")

'If not blank Username password submitted
if UserName <> "" or Password <> "" then
    '
Creating connection Object
    set Conn=server.createobject("ADODB.Connection")
    'Creating Recordset Object
    set rs = Server.CreateObject("ADODB.Recordset")
    '
Initialising Provider String
    connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source="
    connStr = connStr + server.MapPath("Studentrecords.mdb")

    'Opening Connection to Database
    Conn.open  connStr
   
    '
Query to be executed
    SQLQuery = "select * from tblStudent where StudentNo = '"&UserName&"' AND Password = '"&Password&"'"

    'Retrieving recordset by executing SQL
    set rs=Conn.execute(SQLQuery)
    '
If no records retrieved
    if rs.BOF and rs.EOF then
        Response.Redirect "login.asp?username=" & UserName
    else
        'If remember me selected
        if RememberMe = "ON" then
            '
Writing cookies permanently
            Response.Cookies("UserName")=UserName
            Response.Cookies("Password")=Password
            Response.Cookies("UserName").Expires = Now() + 365
            Response.Cookies("Password").Expires = Now() + 365
            Response.Redirect "welcome.asp"
        else
            'writing cookies temporarily
            Response.Cookies("UserName")=UserName
            Response.Cookies("Password")=Password
            Response.Redirect "welcome.asp"
        end if
        '
Closing all database connections
        Conn.Close
        rs.close   
        set rs = nothing
        set Conn = nothing
    end if
else
    'Invalid User
    Response.Redirect "login.asp?UserName=blank"
end if
%>

Upload the all the 3 files viz login.asp, verify.asp and Studentrecords.mdb in the current folder and you are ready to go.

archu 12Mar2007 13:06

Re: Simple Login in ASP using MS Access database
 
Hello

if i want to login using userid or email then what will be the code??

Thank u

shabbir 12Mar2007 13:24

Re: Simple Login in ASP using MS Access database
 
Quote:

Originally Posted by archu
if i want to login using userid or email then what will be the code??

StudentNO can behave as that. The concenptually article will explain how to go about it and it can always be extended for the custom fields in the database.

archu 12Mar2007 14:12

Re: Simple Login in ASP using MS Access database
 
Hi,

Thanks for the reply. I think you din't get my point. I am asking for the code which help me to login using both username and email id . Ie is if i want i can login with a user name. Or else with a email id . The same way which is there in monster.com

Thanks in advance.

bye

shabbir 12Mar2007 15:56

Re: Simple Login in ASP using MS Access database
 
Quote:

Originally Posted by archu
Thanks for the reply. I think you din't get my point. I am asking for the code which help me to login using both username and email id . Ie is if i want i can login with a user name. Or else with a email id . The same way which is there in monster.com

Still my answer remains the same but i will add something more.

If one verification process fails you can go with the other but you can also test if the username contains some predefined valid email format and then go for email validation or the username one.

kimnhat 15Mar2007 02:39

Re: Simple Login in ASP using MS Access database
 
Hi,

I try to apply you code in Macromedia MX asp vbscript page and it not verify the username and password. Could you please let me know what I did wrong. I am new to this software and I try to create simple webpage with user name and password. please help

shabbir 15Mar2007 07:26

Re: Simple Login in ASP using MS Access database
 
Did you try creating a normal ASP page and see if it works for you.

kimnhat 15Mar2007 18:55

Re: Simple Login in ASP using MS Access database
 
Hi Shabbir,

It actualy work but it no validate the username and password. I can login either username and passowd blank or I just type some thinf in those 2 field. When I click login it link to verify page. Thanks,

shabbir 15Mar2007 19:56

Re: Simple Login in ASP using MS Access database
 
There is a check for blank username and password and so see if it is executed correctly and if not it should display the message
Code:

if UserName <> "" or Password <> "" then
.
.
.
else
    'Invalid User
    Response.Redirect "login.asp?UserName=blank"
end if


kimnhat 15Mar2007 21:29

Re: Simple Login in ASP using MS Access database
 
Hi Shabbir,

My bad. I were missing some code that why it not works. Now it works fine. Thanks alot.

shabbir 16Mar2007 06:44

Re: Simple Login in ASP using MS Access database
 
Quote:

Originally Posted by kimnhat
Hi Shabbir,

My bad. I were missing some code that why it not works. Now it works fine. Thanks alot.

My pleasure.

archu 17Mar2007 14:50

Re: Simple Login in ASP using MS Access database
 
Hi shabeer,

I have a problem. I have designed a form which takes the details from the user and stores in a database. till storing i was not finding any problem. Now i am giving edit / update for the same form. I want to assign values to the each feild , which is already available in the database. I know how to assign for a text box. but i am finding difficulty in case of a radiobutton/ check box/ list. Pls help me know.

Thanks in advance

shabbir 17Mar2007 15:20

Re: Simple Login in ASP using MS Access database
 
For check box / radio button there is a value attribute which will be set if that is selected and you can determine which one is selected provided you have unique values for each and then you can update the database accordingly.

hello 6May2007 03:39

Re: Simple Login in ASP using MS Access database
 
Hi I am new here. I am making forum and there i want login page first before view yhe forum and i am making this project in asp.net with c# so can anyone tell me how can i do this and one thing mor i am working with master page so also explain how can i make this in master page

Thanks in advance :)

Pedes69 4Dec2007 09:08

Re: Simple Login in ASP using MS Access database
 
Dear shabbir,

Your code is working perfect, thank you for sharing this.

But i have a question.

I would like to direct diffent users to diffent pages.
Like this:
-> User A has to redirect to page welcome1.asp
-> User B has to redirect to page welcome2.asp
-> User C has to redirect to page welcome3.asp
-> User D has to redirect to page welcome1.asp
and so on...

Can you tell me how to implement this in you code.

Thank you very much
Peter

shabbir 4Dec2007 09:29

Re: Simple Login in ASP using MS Access database
 
Just redirect after validating. You need to check the type of user which is also fetched when validating the user and then use the ASP's redirect function.

cybermarc 4Jan2008 16:53

Re: Simple Login in ASP using MS Access database
 
I want to keep my database in a separate folder but the script won't work.

connStr = connStr + server.MapPath("/private/mrecords.mdb")

anything wrong with this?

mendir200 13Feb2008 21:24

Re: Simple Login in ASP using MS Access database
 
Hey Shabbir, great code!!

I implemented it to check a MS Access field for an email address. The problem is I set it up so that if a user accidentally types in the wrong address, they are re-directed to a page that allows them to re-enter the address again. If they re-enter the correct Email from that page, they get this message: “ADODB.Recordset error '800a0e78' Operation is not allowed when the object is closed”.


I looked into the problem and I believe it is a syntax issue, ref: http://databases.aspfaq.com/database...look-like.html

Thanks so much!

shabbir 13Feb2008 21:45

Re: Simple Login in ASP using MS Access database
 
Yes its a syntax issue and you need to have the Recordset open to execute the SQL.

biztalk 25Feb2008 06:17

Re: Simple Login in ASP using MS Access database
 
I would also like to do I would like to direct diffent users to diffent pages.
Like this:
-> User A has to redirect to page welcome1.asp
-> User B has to redirect to page welcome2.asp
-> User C has to redirect to page welcome3.asp
-> User D has to redirect to page welcome1.asp
and so on...

Is it possbile for you to give the code for this?

shabbir 25Feb2008 09:26

Re: Simple Login in ASP using MS Access database
 
Just write the set of if's and then Response.Redirect to the correct page unless you have some definite logic for the redirection.

biztalk 26Feb2008 12:49

Re: Simple Login in ASP using MS Access database
 
So you mean like this

Normal
'If remember me selected
if RememberMe = "ON" then
'Writing cookies permanently
Response.Cookies("UserName")=UserName
Response.Cookies("Password")=Password
Response.Cookies("UserName").Expires = Now() + 365
Response.Cookies("Password").Expires = Now() + 365
Response.Redirect "welcome.asp"
else
'writing cookies temporarily
Response.Cookies("UserName")=UserName
Response.Cookies("Password")=Password
Response.Redirect "welcome.asp"
end if

My version
'If remember me selected
if RememberMe = "ON" then
'Writing cookies permanently
Response.Cookies("UserName")=test
Response.Cookies("Password")=test
Response.Cookies("UserName").Expires = Now() + 365
Response.Cookies("Password").Expires = Now() + 365
Response.Redirect "test.asp"
else
'writing cookies temporarily
Response.Cookies("UserName")=test
Response.Cookies("Password")=test
Response.Redirect "test.asp"
end if

nednilbor 8Mar2008 09:54

Re: Simple Login in ASP using MS Access database
 
do you have any sample code for the signup.asp so that new users could sign up?

carrathanatos 19Jun2008 21:43

Re: Simple Login in ASP using MS Access database
 
Hey, I copy and pasted your code over and created the database with microsoft access, and I keep getting this error:

HTTP 500.100 - Internal Server Error - ASP error
Internet Information Services

Technical Information (for support personnel)

* Error Type:
Microsoft JET Database Engine (0x80040E10)
No value given for one or more required parameters.
/news/verify.asp, line 37

* Browser Type:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0

* Page:
POST 45 bytes to /news/verify.asp

I'm not sure why either...

thanks for your help,

melissa

carrathanatos 19Jun2008 21:50

Re: Simple Login in ASP using MS Access database
 
biztalk:

make an extra field in the DB for each user called something like "redirectPage" or something, and then for the redirect where it says:

Response.Redirect "blah blah blah", replace with:

Set rsStudent = Server.CreateObject("ADODB.Recordset") 'this should go near the top of your code
Response.Redirect rsStudent("redirectPage")

and then at the end be sure to put:

rsStudent.Close
set rsStudent = Nothing

hope that helps! :)

carrathanatos 19Jun2008 21:51

Re: Simple Login in ASP using MS Access database
 
(the ifs are too messy, and it's much easier to just include it in our DB.)

kseanng 3Jul2008 20:38

Re: Simple Login in ASP using MS Access database
 
Hey guys,

I got this error message.

The page cannot be displayed
There is a problem with the page you are trying to reach and it cannot be displayed.

--------------------------------------------------------------------------------

Please try the following:

Click the Refresh button, or try again later.

Open the fica home page, and then look for links to the information you want.
HTTP 500.100 - Internal Server Error - ASP error
Internet Information Services

--------------------------------------------------------------------------------

Technical Information (for support personnel)

Error Type:
Microsoft JET Database Engine (0x80040E10)
No value given for one or more required parameters.
/verify.asp, line 38


Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)

Page:
POST 36 bytes to /verify.asp

POST Data:
username=????&password=????&B1=LogIn

Time:
Thursday, July 03, 2008, 10:03:38 AM


More information:
Microsoft Support

carrathanatos 3Jul2008 23:07

Re: Simple Login in ASP using MS Access database
 
If you're suffering the same problem as me, the closest I've been able to get to a pseudo-solution is that the actual CDONTS/CDOSYS cannot send the mail out because the port is being blocked by a firewall of some sort, or that the settings on the server won't allow mail to be sent out.

I don't have a system admin because they won't hire one, so I'm kind of stuck in cold water.

I hope you solve yours though....

oh, just to clarify, if you're having the same problem as me, then it's not a code problem, it's a server problem.

XXxxImmortalxxXX 7Jul2008 15:59

Re: Simple Login in ASP using MS Access database
 
got a question im looking for some scripts.

A sql detection script created in asp

a script to do a forgot password link


if any of you guys know one can u please post it thanks

kseanng 7Jul2008 23:05

Re: Simple Login in ASP using MS Access database
 
carrathanatos,

I figured out what was wrong with my code. In access database I named the column wrong. Here's a link. I hope this helps. http://www.adopenstatic.com/faq80040e10.asp

ashley 25Nov2008 02:19

Re: Simple Login in ASP using MS Access database
 
This is a great script!

I have a database our sales people use. I'd like to restrict their data to their login; ie. username CD from tblLogin can only see data from tblSales salesID=CD.

Thanks in advance!

ashley 25Nov2008 02:45

Re: Simple Login in ASP using MS Access database
 
I forgot to post how my tables are set up:

tblLogin:
username
name
password

tblSales:
key
salesID

The username from tblLogin will match an entry in salesID, ie. username = CD, salesID = CD.

The login 'admin' needs to access the entire database.

I'm new to programming in asp. I think it's an if statement like if username = "", where username=salesID, then... I'm really not sure though!

kumaaar 26Nov2008 17:44

Re: Simple Login in ASP using MS Access database
 
when i checked the pages its going to the verify page (and showing a blank page of verify )
even if i do any thing with the login parameters.. pls help is thr any mistake in the code..

robinLee01 24Feb2009 01:26

Re: Simple Login in ASP using MS Access database
 
Hi,
I am new to both microsoft access and asp....but i am trying to lerans ways to link a database and a webpage and saw ur codes....i did as u said in the forum...but i wanst sure what to do next... i mean, i have all the three files in one folder, and what next? how would i check if it worked?
Thanks in advance
Robin

shabbir 24Feb2009 09:53

Re: Simple Login in ASP using MS Access database
 
Trying to see them in browsers should be the nest step

Ryan_Wilcox 27Jul2011 12:00

Re: Simple Login in ASP using MS Access database
 
Hi all I need help as I get this error, I am new to asp, and this is for a school assignment.

Microsoft JET Database Engine error '80040e10'
No value given for one or more required parameters.
/students/IPT/12IPT2011/007378/Term 3/verify.asp, line 32

Here is my code! (These are the code lines around this area of the error)

'Opening Connection to Database
Conn.open connStr
'Query to be executed
SQLQuery = "select * from tbl_CustomerInfo where Customer_ID = '"&Customer_ID&"' AND Cusotmer_Pass = '"&Password&"'"
'Retrieving recordset by executing SQL
set rs=Conn.execute(SQLQuery)
'If no records retrieved
if rs.BOF and rs.EOF then
Response.Redirect "index.asp?Customer_ID=" & Customer_ID
else

Ryan_Wilcox 27Jul2011 15:15

Re: Simple Login in ASP using MS Access database
 
So sorry for the post, just read over the code myself after getting home, and realised it was a stupid spelling mistake.

Sorry again.


All times are GMT +5.5. The time now is 19:08.