Help with my login script :(

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2009
Posts: 6
Reputation: adam1991 is an unknown quantity at this point 
Solved Threads: 0
adam1991 adam1991 is offline Offline
Newbie Poster

Help with my login script :(

 
0
  #1
Oct 5th, 2009
Here is the code first off all for the login script (HTML)

  1.  
  2. <form id="form1" runat="server" method="post">
  3. <asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>
  4. <asp:TextBox ID="txtPassword"
  5. runat="server" style="width: 128px"></asp:TextBox>
  6. <asp:Button ID="Button1" runat="server" Text="Login" />

Here is the behind code to that page double click on the button and get this code (VB.NET)

  1. Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("database\UsersPasswords.mdb"))
  2. Try
  3. Dim query As New OleDbCommand("SELECT COUNT(*) AS Result, Username AS UsernameInput, [Password] AS PasswordInput FROM(UsersPasswords)GROUP BY Username, [Password]HAVING (COUNT(*) = 1) AND (Username = '" & txtUsername.Text & "') AND ([Password] = '" & txtPassword.Text & "')", conn)
  4.  
  5. conn.Open()
  6. Dim datareader As OleDbDataReader = query.ExecuteReader()
  7. datareader.Read()
  8.  
  9. If datareader.Read = True Then
  10. Label1.Text = ("You are logged in")
  11. Else
  12. Label1.Text = ("Wrong Username or Password")
  13. End If
  14. conn.Close()
  15. Catch ex As Exception
  16. Label1.Text = (ex.Message)
  17. End Try
  18. End Sub

The problem is that when i type in the correct username and password from the database it just keeps saying "wrong password" ive tried a number of diffrent querys but im unable to fix it

Thanks for your help!
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 155
Reputation: vuyiswamb is an unknown quantity at this point 
Solved Threads: 5
vuyiswamb's Avatar
vuyiswamb vuyiswamb is offline Offline
Junior Poster

Re: Help with my login script :(

 
0
  #2
Oct 5th, 2009
This is not A Correct Approach for a login. This is simple you are Suppose to count the Records that matches the Where Clause and you have included having and Group by clause and that is incorrect. You need a simple statement like this

  1. SELECT COUNT(*) FROM UsersPasswords
  2. WHERE Username = [USERNAMEPARAMER] AND Password =[PASSWORDPARAMTER]

I Have once gave someone an answer , please search any post by me here on the Forum
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 6
Reputation: adam1991 is an unknown quantity at this point 
Solved Threads: 0
adam1991 adam1991 is offline Offline
Newbie Poster

Re: Help with my login script :(

 
0
  #3
Oct 5th, 2009
Are you sayin the whole login is the wrong way to do it.. or you sayin just the query is the wrong way?

Ive just tried that query and it is sayin wrong username or password even though i typed in the right information

thanks
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 155
Reputation: vuyiswamb is an unknown quantity at this point 
Solved Threads: 5
vuyiswamb's Avatar
vuyiswamb vuyiswamb is offline Offline
Junior Poster

Re: Help with my login script :(

 
0
  #4
Oct 5th, 2009
Look at this Post and tell me if there is still a problem

http://www.daniweb.com/forums/thread138587.html


Kind Regards


Vuyiswa Maseko
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 206
Reputation: plazmo is an unknown quantity at this point 
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: Help with my login script :(

 
0
  #5
Oct 5th, 2009
Originally Posted by adam1991 View Post
Here is the code first off all for the login script (HTML)

  1.  
  2. <form id="form1" runat="server" method="post">
  3. <asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>
  4. <asp:TextBox ID="txtPassword"
  5. runat="server" style="width: 128px"></asp:TextBox>
  6. <asp:Button ID="Button1" runat="server" Text="Login" />

Here is the behind code to that page double click on the button and get this code (VB.NET)

        Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("database\UsersPasswords.mdb"))
        Try
            Dim query As New OleDbCommand("SELECT        COUNT(*) AS Result, Username AS UsernameInput, [Password] AS PasswordInput FROM(UsersPasswords)GROUP BY Username, [Password]HAVING        (COUNT(*) = 1) AND (Username = '" & txtUsername.Text & "') AND ([Password] = '" & txtPassword.Text & "')", conn)

conn.Open()
            Dim datareader As OleDbDataReader = query.ExecuteReader()
            datareader.Read()

            If datareader.Read = True Then
                Label1.Text = ("You are logged in")
            Else
                Label1.Text = ("Wrong Username or Password")
            End If
            conn.Close()
        Catch ex As Exception
            Label1.Text = (ex.Message)
        End Try
    End Sub

The problem is that when i type in the correct username and password from the database it just keeps saying "wrong password" ive tried a number of diffrent querys but im unable to fix it

Thanks for your help!
datareader.Read() is advancing your data reader to the next row. If there is only 1 row then the next row would be empty. delete that and it should work.(i have it bold)
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: I.Ahmad is an unknown quantity at this point 
Solved Threads: 0
I.Ahmad I.Ahmad is offline Offline
Newbie Poster
 
0
  #6
Oct 7th, 2009
U should try this simple query as
dim aurery as oledbcommand=new oledbcommad("select * from <tablename> where username='" & txtuname.text & "' and password='" & txtpasword.text & "')"

dim dr as oledbdatareader=query.executereader()
if dr.read=true then
label1.text="you r welcome"
else
label1.text="wrong pasword"
end if


Enjoy coding..
u can direct contact me on imteyazahmad86@gmail.com
u r alwz welcome
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC