login with ms access table

Thread Solved

Join Date: Jul 2007
Posts: 193
Reputation: plusplus is an unknown quantity at this point 
Solved Threads: 16
plusplus plusplus is offline Offline
Junior Poster

login with ms access table

 
0
  #1
Jun 26th, 2008
I have a login control, when user presses login I want to check if he exists in the table.
I made a connection to database, and now how do I check if he exists?

Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
Dim sqlstring As String
sqlstring = "SELECT id FROM tbl_users WHERE name = " & Login1.UserName & "AND password= " & Login1.Password
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\Dokumente und Einstellungen\USER\Eigene Dateien\Login.mdb;User Id=admin;Password=;")
Dim dbcomm As New OleDbCommand(sqlstring, cn)


cn.Dispose()
End Sub
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 125
Reputation: bala24 is an unknown quantity at this point 
Solved Threads: 11
bala24's Avatar
bala24 bala24 is offline Offline
Junior Poster

Re: login with ms access table

 
0
  #2
Jun 26th, 2008
Call Executescalar with your command object. It returns a single value like id in your case if the query is successful.

If it is nothing then the login fails, otherwise, allow the user.
Michelangelo

"The best place to find a helping hand is at the end of your own arm"
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 193
Reputation: plusplus is an unknown quantity at this point 
Solved Threads: 16
plusplus plusplus is offline Offline
Junior Poster

Re: login with ms access table

 
0
  #3
Jun 26th, 2008
I need some more help, I don't know how to go about it
In web.config I have
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
<authentication mode="Forms"/>

In my login form I have a login control with this code

Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
Dim sqlstring As String
sqlstring = "SELECT id FROM tbl_users WHERE name = " & Login1.UserName & "AND password= " & Login1.Password
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\Dokumente und Einstellungen\USER\Eigene Dateien\Login.mdb;User Id=admin;Password=;")
Dim dbcomm As New OleDbCommand(sqlstring, cn)


cn.Dispose()
End Sub

Now if I add to the above code
if dbcomm.executescalar <> nothing then ??????? what do I do to tell my web.config login was successfull?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 125
Reputation: bala24 is an unknown quantity at this point 
Solved Threads: 11
bala24's Avatar
bala24 bala24 is offline Offline
Junior Poster

Re: login with ms access table

 
0
  #4
Jun 27th, 2008
Try this article.
It will clarify your doubts about form authentication.

http://www.eggheadcafe.com/articles/20020906.asp

If you think that's difficult to digest, go through this one..

http://www.csse.monash.edu.au/course...004/login.html
Hope this helps.
Last edited by bala24; Jun 27th, 2008 at 2:45 am.
Michelangelo

"The best place to find a helping hand is at the end of your own arm"
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 193
Reputation: plusplus is an unknown quantity at this point 
Solved Threads: 16
plusplus plusplus is offline Offline
Junior Poster

Re: login with ms access table

 
0
  #5
Jun 27th, 2008
I'll take a look at it, but maybe you know a place with vb code not c?
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 193
Reputation: plusplus is an unknown quantity at this point 
Solved Threads: 16
plusplus plusplus is offline Offline
Junior Poster

Re: login with ms access table

 
0
  #6
Jun 27th, 2008
Originally Posted by bala24 View Post
Try this article.
It will clarify your doubts about form authentication.

http://www.eggheadcafe.com/articles/20020906.asp

If you think that's difficult to digest, go through this one..

http://www.csse.monash.edu.au/course...004/login.html
Hope this helps.
I'll try it out and get back if I need some more help.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 125
Reputation: bala24 is an unknown quantity at this point 
Solved Threads: 11
bala24's Avatar
bala24 bala24 is offline Offline
Junior Poster

Re: login with ms access table

 
0
  #7
Jun 27th, 2008
Well the second url I sent is in vb and its quite easy to understand as well.

Try that one.
Michelangelo

"The best place to find a helping hand is at the end of your own arm"
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 193
Reputation: plusplus is an unknown quantity at this point 
Solved Threads: 16
plusplus plusplus is offline Offline
Junior Poster

Re: login with ms access table

 
0
  #8
Jun 30th, 2008
Here is what I have so far, the bold line gives me an error, besides does this code look right?

Dim myid As Long
Dim sqlstring As String
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\Dokumente und Einstellungen\USER\Eigene Dateien\Login.mdb;User Id=admin;Password=;")
Dim dr As New OleDbDataReader
sqlstring = "SELECT id FROM tbl_users WHERE name = ? AND password= ?"
Dim dbcomm As New OleDbCommand(sqlstring, cn)

dbcomm.Parameters.AddWithValue("name", Login1.UserName)
dbcomm.Parameters.AddWithValue("password", Login1.Password)

If dbcomm.ExecuteScalar <> Nothing Then
dr = dbcomm.ExecuteReader()
myid = dr(1)
System.Web.Security.FormsAuthentication.RedirectFromLoginPage(myid, False)
End If

cn.Dispose()
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 125
Reputation: bala24 is an unknown quantity at this point 
Solved Threads: 11
bala24's Avatar
bala24 bala24 is offline Offline
Junior Poster

Re: login with ms access table

 
0
  #9
Jun 30th, 2008
Well you don't need that line at all.
The ExecuteScalar method returns a single value eg the number of records affected in an update query.
In your case it holds the id of the user which is an authenticated user.

If he is not, the ExecuteScalar will return nothing.

So what you could do id this.

  1. Dim strid as string 'Assuming your id is a string value
  2.  
  3. strid=dbcomm.ExecuteScalar()
  4.  
  5. If not strid is nothing Then
  6. System.Web.Security.FormsAuthentication.RedirectFromLoginPage(strid, False)
  7. End If
  8.  

Hope its clear.
Michelangelo

"The best place to find a helping hand is at the end of your own arm"
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 2147 | Replies: 8
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC