|
-
Jun 25th, 2004, 06:11 AM
#1
Thread Starter
Addicted Member
Password validation
Hi all,
i am trying to write a password validation function, here is what i have so far:
Code:
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
'validate user login
'check both fields contain some info
If txtUserName.Text = "" Or txtPassword.Text = "" Then
MsgBox("You must enter a valid username and password to continue. Blank fields are not accepted.")
Else
'grab the user input
uname = txtUserName.Text
pwd = txtPassword.Text
'create filter/dataiew
Dim dv As New DataView(DsLogin1.Tables("tblpwd"))
dv.RowFilter = "Username = 'uname' AND Password = 'pwd'"
If dv.Count = 1 Then
'open main form
Dim frm1 As New frmMain
frm1.Show()
Else
MsgBox("You have entered an invalid password, please try again.")
End If
End If
End Sub
It runs but doesn't find the username or password.
any help appreciated.
-
Jun 25th, 2004, 07:34 AM
#2
Hyperactive Member
At first glance, my guess is that you are referencing a table that doesn't exist in your dataset, "tblpwd" but I don't know how this dataset is getting populated or how you know that the name of the table is "tblpwd".
If you are accessing data and filling a dataset in the usual way then your table name is probably not "tblpwd" as you expect, but is actually "Table".
The reason is when you fill a dataset using the dataadapter.fill method, event though your select statement indicates what table you are selecting data from, your dataset names it "Table", "Table2" . . . etc.
Try altering this line:
VB Code:
Dim dv As New DataView(DsLogin1.Tables("tblpwd"))
to this:
VB Code:
Dim dv As New DataView(DsLogin1.Tables("Table"))
-
Jun 25th, 2004, 08:10 AM
#3
Thread Starter
Addicted Member
Hi and thanks for yout reply,
I am filling the dataset at the time the form is loaded:
Code:
conn1.open()
oleda.Fill(dslogin)
I have tried replacing the tblpwd with Table in it still returns exactly the same
-
Jun 25th, 2004, 08:26 AM
#4
PowerPoster
Originally posted by dagoose
Hi and thanks for yout reply,
I am filling the dataset at the time the form is loaded:
Code:
conn1.open()
oleda.Fill(dslogin)
I have tried replacing the tblpwd with Table in it still returns exactly the same
Looks like you have not populated oleda
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 25th, 2004, 08:30 AM
#5
Hyperactive Member
Not necessarily taxes, if he is referencing the wrong table, or is not providing valid values for his rowfilter property then he could be receiving an empty value when he queries his dataview.
How many tables are in your dataset?
Also, are you absolutely certain that you are passing a valid username and password in your rowfilter. I have code here that works just fine and does return the one row that I expect it to.
VB Code:
Private Sub btnGetCustInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetCustInfo.Click
Dim dt As New DataTable("Customers")
dt.Columns.Add("location", System.Type.GetType("System.String"))
dt.Columns.Add("country", System.Type.GetType("System.String"))
dt.Columns.Add("lasttime", System.Type.GetType("System.String"))
Dim oReader As New StreamReader("C:\bin\LastImport.CSV")
Dim oCust As String
Dim Delim As String = ","
Dim oData() As String
Dim Index As Int32
Dim drItem As DataRow
oCust = oReader.ReadLine
Do
oData = oCust.Split(Delim.ToCharArray)
drItem = dt.NewRow
For Index = oData.GetLowerBound(0) To oData.GetUpperBound(0)
drItem(Index) = oData(Index).ToString
Next
dt.Rows.Add(drItem)
drItem = Nothing
oCust = oReader.ReadLine
Loop Until oCust Is Nothing
Dim dv As New DataView(dt)
dv.RowFilter = "location = '510'"
Me.DataGrid1.DataSource = dv
End Sub
-
Jun 25th, 2004, 08:37 AM
#6
PowerPoster
Originally posted by CyberHawke
Not necessarily taxes, if he is referencing the wrong table, or is not providing valid values for his rowfilter property then he could be receiving an empty value when he queries his dataview.
Doesn't he have to populate the dataadapter AFTER he has opened the connection?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 25th, 2004, 08:57 AM
#7
Hyperactive Member
No, the code is correct asuming that the dataadapter is a module level object that already has a command associated with it.
What he does not have to do is open his connection. As long as it is associated with the dataadapter, it will open long enough to retrieve his data and the automatically close again.
-
Jun 25th, 2004, 09:59 AM
#8
PowerPoster
Originally posted by CyberHawke
No, the code is correct asuming that the dataadapter is a module level object that already has a command associated with it.
What he does not have to do is open his connection. As long as it is associated with the dataadapter, it will open long enough to retrieve his data and the automatically close again.
But if what he posted is the first, and only, time he opened the connection...........?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 25th, 2004, 10:45 AM
#9
Hyperactive Member
Then it will eventually close again after a period of inactivity. The point is that by explicitly opening a connection, you are using up resources on the server in a wasteful way. It is better to have dynamic connections that are opened and closed as DataAdapters consume them.
-
Jun 25th, 2004, 10:45 AM
#10
Sleep mode
-
Jun 25th, 2004, 05:19 PM
#11
PowerPoster
Originally posted by CyberHawke
Then it will eventually close again after a period of inactivity. The point is that by explicitly opening a connection, you are using up resources on the server in a wasteful way. It is better to have dynamic connections that are opened and closed as DataAdapters consume them.
Sorry but that is nothing to do with what we are discussing. My comment refers to the coding posted as
conn1.open()
oleda.Fill(dslogin)
If this is the only time conn1 is opened, should oleda be then populated before dslogin can be filled?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 2nd, 2004, 12:11 PM
#12
Junior Member
I apologize if I am way off base, I don't really know .NET yet,
but it looks like you are not passing in the variable values of Username and Password:
Should this:
dv.RowFilter = "Username = 'uname' AND Password = 'pwd'"
be structured like this?
dv.RowFilter = "Username = '" & uname & "' AND Password = '" & pwd & '"
-
Jul 2nd, 2004, 12:50 PM
#13
Originally posted by bubba
I apologize if I am way off base, I don't really know .NET yet,
but it looks like you are not passing in the variable values of Username and Password:
Should this:
dv.RowFilter = "Username = 'uname' AND Password = 'pwd'"
be structured like this?
dv.RowFilter = "Username = '" & uname & "' AND Password = '" & pwd & '"
For crimminy sakes! How long was this thread going to go before some one go it right! Took me all of 5 seconds to spot this.
Bravo bubba !
TG
-
Jul 2nd, 2004, 01:01 PM
#14
Junior Member
I guess it takes a simple mind to find the simple solution?
-
Jul 2nd, 2004, 01:08 PM
#15
New Member
That made my day HA HA.
Yeah I didn't notice that either, I was thinking that he did not fill up his dataset correctly.
By golly...
-
Jul 2nd, 2004, 01:21 PM
#16
Originally posted by bubba
I guess it takes a simple mind to find the simple solution?
Ah, don't kid yourself. It's those little things in life. Sometimes when some one has been staring at the same code for too long they can't see what's wrong with it, and it usualy takes a pair of fresh eyes to lookat it.
TG
-
Jul 2nd, 2004, 03:50 PM
#17
Addicted Member
Use this to fill a combobox with all your usernames:
In frmMain.Load Event
Code:
cmbUsername.DataSource = DsEmployeeInformation.Employee_Information
cmbUsername.DisplayMember = "Name"
Then use this to determine a valide password for the selected username:
In btnLogin.Click Event
Code:
With dsEmployeeInformation.Employee_Information
If Convert.ToString(.Rows(cmbUsername.SelectedIndex)("Password")) = txtPassword.Text Then
Dim frmNew As New frmNew
frmNew.showdialog()
Else
MessageBox.Show("Invalid Password!")
txtPassword.Text = ""
End If
End With
Very simple and works great!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|