I need help. Need to do password validation and have no idea why it doesn't work. Could someone tell me what my code is missing or what is actually wrong with my way of thinking? I am connecting it to dataset2 where is the table called Users2. Table consists of two columns: 'Username' and 'Password'. Users2BiningSource.Find should be returning value of an index where a current query is. The returned value is always -1, what I guess means that is not found (false). I am using Microsoft Visual Studio 2012 along with SQL server 2008 SP3, all on windows 7. Thank you for your time and help! - Imports Hotel_Booking_System.DataSet2TableAdapters
-
-
-
-
Public Class Logging
-
-
-
Public Sub check_Click(sender As Object, e As EventArgs) Handles Button1.Click
-
Me.Check_Details()
-
End Sub
-
-
-
Private Sub Quit_Click(sender As Object, e As EventArgs) Handles Button2.Click
-
Me.Close()
-
End Sub
-
-
Public Sub Logging_Load(sender As Object, e As EventArgs) Handles MyBase.Load
-
Me.Users2TableAdapter.Fill(Me.DataSet2.Users2)
-
'TODO: This line of code loads data into the 'DataSet2.Users2' table. You can move, or remove it, as needed.
-
-
End Sub
-
-
Public Sub Check_Details()
-
-
Me.Users2BindingSource.AddNew()
-
-
Dim Usrnm As String = ""
-
Usrnm = txtUsername.Text
-
Dim Pswrd As String = ""
-
Pswrd = txtPassword.Text
-
Dim Found As Integer
-
Found = Users2BindingSource.Find("Username", Usrnm)
-
Dim Found2 As Integer
-
Found2 = Users2BindingSource.Find("Password", Pswrd)
-
-
-
If Found >= 0 And Found2 >= 0 And Usrnm = "Admin" Then
-
Me.Hide()
-
Booking.Show()
-
ElseIf Found >= 0 And Found2 >= 0 Then
-
Me.Hide()
-
Rooms.Show()
-
Else
-
MsgBox("Wrong username or password. Please try again", MsgBoxStyle.DefaultButton1, "SOMETHING WENT WRONG")
-
End If
-
Label1.Text = Found 'checking the value of found
-
Label2.Text = Found2 ' checking the value of found2
-
End Sub
-
-
End Class
4 2694
Hey sampak, alter your code as follows and try again. -
Dim username As String = txtUsername.Text
-
Dim password As String = txtPassword.Text
-
-
Dim found1 As Integer = bs.Find("Username", username)
-
Dim found2 As Integer = bs.Find("Password", password)
-
-
'MsgBox(found1 + " " + found2);
-
-
If found1 <> -1 AndAlso found2 <> -1 Then
-
If found1 = found2 Then
-
'MsgBox("Username and Password matching")
-
-
If username.Equals("Admin") Then
-
Me.Hide()
-
Booking.Show()
-
Else
-
Me.Hide()
-
Rooms.Show()
-
End If
-
ElseIf found2 > found1 Then
-
MsgBox("Invalid Username or Password")
-
Else
-
bs.MoveFirst()
-
-
For i As Integer = 0 To found1 - 1
-
bs.RemoveCurrent()
-
Next
-
-
If bs.Find("Password", password) <> 0 Then
-
MsgBox("Invalid Username or Password")
-
Else
-
'MsgBox("Username and Password matching")
-
-
If username.Equals("Admin") Then
-
Me.Hide()
-
Booking.Show()
-
Else
-
Me.Hide()
-
Rooms.Show()
-
End If
-
End If
-
End If
-
Else
-
MsgBox("Invalid Username or Password")
-
End If
All i want to say is one thing, your method for Username and Password verification is too complex or i maybe wrong. Why you're using 'BindingSource' for Username and Password verification?
The reason I am using BindingSource is I have tried so many different ways, and nothing works... :/ So I am trying with binding source... I want to create simple logging in structure connected with sql database... it is so shit... I ve tried sth like that as well: - Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
-
-
Dim login = Me.Users2TableAdapter.UsernamePassword(txtUsername.Text, txtPassword.Text)
-
If login Is Nothing Then
-
MsgBox("wrong details", , "INCORRECT LOGIN OR PASSWORD")
-
Else
-
MsgBox("welcome")
-
-
-
End If
I have built a simple query where it counter returns number of rows that matches with the password and username have been entered. But it doesnt work as well... all my connections seem to be fine. Why is so hard to work with database? And all my project is database based on. Your solution is not working either.
bs - is it a name of BindingSource yes? it returns me an error saying Properties of DataMemeber 'Username' cannot be found in DataSource element. so frustrating.
So this: - Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
-
-
Dim login = Me.Users2TableAdapter.UsernamePassword(txtUsername .Text, txtPassword.Text)
-
If login Is Nothing Then
-
MsgBox("wrong details", , "INCORRECT LOGIN OR PASSWORD")
-
Else
-
MsgBox("welcome")
-
-
-
End If
work with Access database, but i want to use sql... what is the difference? I am using sql query anyway, so can someone explain me why i doesn't work?
Hey sampak, this is the simple Username and Password verification method. If you want you can try this method, -
Private Sub button1_Click(sender As Object, e As EventArgs)
-
Dim con As New SqlConnection("Your Database Connection String")
-
Dim cmd As New SqlCommand("SELECT COUNT(*) FROM Table_Name WHERE Username = '" + Me.txtUsername.Text.Trim() + "' AND Password = '" + Me.txtPassword.Text.Trim() + "'", con)
-
Try
-
con.Open()
-
If Convert.ToInt32(cmd.ExecuteScalar()) > 0 Then
-
If Me.txtUsername.Text.Trim().Equals("Admin") Then
-
' Do the respective work for Admin user
-
Else
-
' Do the respective work for Non-Admin user
-
End If
-
Else
-
MessageBox.Show("Invalid Username or Password")
-
End If
-
Catch ex As Exception
-
Console.WriteLine(ex.ToString())
-
Finally
-
con.Close()
-
End Try
-
End Sub
Note: In line number 3 'Username' and 'Password' are refers to the fields in 'Table_Name' table.
In my earlier post 'bs' is 'BindingSource' and 'Username' is one of the field of my table which i fetched into 'bs'.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Corepaul |
last post by:
I am a beginner, using Access 2000.
I am having difficulty with the Visual Basic Help. Specifically, using the
Index tab, when I enter "OpenRecordset" in the keyword field and click the
Search...
|
by: Microsoft |
last post by:
Hi,
I have Visual Basic .net 2003 (Standard Edition) & SQL Server 2000 Developer Edition. When trying to create a connection in the server explorer from the .net IDE I get a number of problems;...
|
by: code_wrong |
last post by:
Visual Basic (not dot net)
what is the best way to check the User has entered an integer into an
InputBox?
isNumeric() checks for a numeric value .. but does not notify of numbers
with decimal...
|
by: marknoten |
last post by:
I have an excel file with columns A, B, C, D and E that look like this:
A B C D E
-----------------------------------------------------
N 23,179 15,744...
|
by: DUNXALEARE |
last post by:
Hello everyone!
I have a new assignment. I just dont know how to create a data report using ms excell.
I need to search particular group of data/records using Visual basic 6. in MS Access and...
| |
by: AjGrace |
last post by:
Hi!
Im a Beginner in SQL server and I need to know how to connect to it using Visual Basic 6.0 using Ado connection..Thanks In Advance guys!
|
by: shangardezi |
last post by:
hi im a beginner with visual basic. I was wondering can someone tell me how i can somehow do a thing that when someone presses ok on the LOGIN FORM, the username and password is sent to my email. im...
|
by: ashokbio |
last post by:
I want to create an associative array, similar to PERL language, using Visual Basic 6.
Example: Using PERL
%A = ("A"=>"Apple","B"=>"Banana");
i.e., A is associated to the word Apple and B...
|
by: gnawoncents |
last post by:
Greetings,
I have a database which uses VBA to dynamically create a report and add VB coding to the on close and on open events. All this works fine, however, when the report closes, the Visual...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |