473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need help with login form

i am connecting to access database(accdb) and created log in form in vb.net.Even if i type correct username.password and role it shows unauthorized user.
i am having this code on my log in button
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub btnloginlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnloginlogin.Click
  3.  
  4. Try
  5. con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database1.accdb;Persist Security Info=False;")
  6.             If con.State = ConnectionState.Closed Then
  7.                 con.Open()
  8.             End If
  9.             com = New OleDbCommand("SELECT * from tbllogin WHERE [User Name]='" & txtloginusname.Text & " ' And Password = ' " & txtloginpassword.Text & " ' And [Application/Role] = ' " & cmbloginrole.Text & " '", con)
  10.             ds = New DataSet
  11.             dap = New OleDbDataAdapter(com)
  12.             dap.Fill(ds, "tbllogin")
  13.             If con.State = ConnectionState.Open Then
  14.                 con.Close()
  15.             End If
  16.             If ds.Tables(0).Rows.Count() <> 0 Then
  17.                 If cmbloginrole.Text = "Administrator" Then
  18.                     AdministratorHomePage.Show()
  19.                     Me.Hide()
  20.                 Else
  21.                     MsgBox("UNAUTHORIZED USER")
  22.                     txtloginusname.Text = ""
  23.                     txtloginpassword.Text = ""
  24.                     cmbloginrole.Text = ""
  25.                 End If
  26.             Else
  27.                 MsgBox("UNAUTHORIZED USER")
  28.                 txtloginusname.Text = ""
  29.                 txtloginpassword.Text = ""
  30.                 cmbloginrole.Text = ""
  31.             End If
  32.  
  33.         Catch ex As Exception
  34.  
  35.             MsgBox(ex.Message)
  36.  
  37.         End Try
  38.  
  39.     End Sub
  40. End Class
  41.  
Feb 6 '14 #1
3 1065
Luk3r
300 256MB
Your code doesn't actually show as you trying to pass credentials (specifically a password) to access the database. In your connection string you need to include a password if the database has one. Here is website that has a list of proper connection strings for you:
http://www.connectionstrings.com/access-2007/
Feb 6 '14 #2
mcupito
294 256MB
Why aren't you using
Expand|Select|Wrap|Line Numbers
  1. Dim
to declare new variables? Also, check your DataSet and DataAdapter.
Are you sure
Expand|Select|Wrap|Line Numbers
  1. ds.Tables(0).Rows.Count
is pointing to the correct fields? Is "0" the correct index?

Also, for your Textbox
Expand|Select|Wrap|Line Numbers
  1. cmbloginrole.Text = "Administrator"
It might be wise to trim the text in the text box. This can be done by a variable or
Expand|Select|Wrap|Line Numbers
  1. .Text.Trim
See here:
Expand|Select|Wrap|Line Numbers
  1.         Dim login As String
  2.         Dim msg As String
  3.  
  4.         login = txt1.Text.Trim
  5.         msg = "Good"
  6.  
  7.         If login = "admin" Then
  8.             txt2.Text = msg
  9.         End If
I hope this helps you in some way.
Feb 6 '14 #3
hy rahul if you Checking "username" and "password" manually than why using OLEDB connection and command..first try with DRY RUN with STATIC VALUE.

Hope you got my reply.

Have a happy coding
Feb 7 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Rudi Groenewald | last post by:
Hi there... I use SQL server integrated security so when a user opens a database in access it prompts the username & password in a small popup box on connection, but I'd like to use my own...
5
by: JPSutor | last post by:
I have a login form, that if successfully answered, launches another form. The problem is that the login form remains even after I show the main form. How do I get rid of the login form?
2
by: pv | last post by:
Hi everyone, I need help with following scenario, please: Users are accessing same web server from intranet (users previously authenticated in Active Dir) and from extranet (common public...
4
by: Johnnie Miami | last post by:
I'm using VB.Net 2005 beta 2 and have my login form (login.vb) specified as the startup form. If the user is successful logging in, I call my main form (main.vb). This all works fine but the...
5
by: Ronald S. Cook | last post by:
It's been longer that I remember since writing windows (not web) apps. 1) I want to load a main form 2) User clicks login button which brings up login form (on top of main form) 3) Upon...
11
yoda
by: yoda | last post by:
The code is: Option Explicit Public LoginSucceeded As Boolean Private Sub cmdCancel_Click() 'set the global var to false 'to denote a failed login LoginSucceeded = False
1
by: postmanpat | last post by:
i have to create a login form that validates the users and passwords from a text file. I have another function that can add new users and passwords by writing to a test file split by a delimiter. But...
8
by: Harris Kosmidhs | last post by:
Hello, while I'm developing sites for some time I never coded a login form with security in mind. I was wondering what guidelines there are. For my point of view I'm thinking of using md5...
1
pbala
by: pbala | last post by:
How to Show the MDI Form with the Log in form while MDI form load for ex. http://G:\bala\Fax\Notes\Dock or Tie.JPG
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.