Results 1 to 17 of 17

Thread: Password validation

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Location
    North east UK
    Posts
    129

    Question 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.

  2. #2
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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:
    1. Dim dv As New DataView(DsLogin1.Tables("tblpwd"))
    to this:
    VB Code:
    1. Dim dv As New DataView(DsLogin1.Tables("Table"))

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Location
    North east UK
    Posts
    129
    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

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  5. #5
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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:
    1. Private Sub btnGetCustInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetCustInfo.Click
    2.         Dim dt As New DataTable("Customers")
    3.         dt.Columns.Add("location", System.Type.GetType("System.String"))
    4.         dt.Columns.Add("country", System.Type.GetType("System.String"))
    5.         dt.Columns.Add("lasttime", System.Type.GetType("System.String"))
    6.         Dim oReader As New StreamReader("C:\bin\LastImport.CSV")
    7.         Dim oCust As String
    8.         Dim Delim As String = ","
    9.         Dim oData() As String
    10.         Dim Index As Int32
    11.         Dim drItem As DataRow
    12.         oCust = oReader.ReadLine
    13.         Do
    14.             oData = oCust.Split(Delim.ToCharArray)
    15.             drItem = dt.NewRow
    16.             For Index = oData.GetLowerBound(0) To oData.GetUpperBound(0)
    17.                 drItem(Index) = oData(Index).ToString
    18.             Next
    19.             dt.Rows.Add(drItem)
    20.             drItem = Nothing
    21.             oCust = oReader.ReadLine
    22.         Loop Until oCust Is Nothing
    23.         Dim dv As New DataView(dt)
    24.         dv.RowFilter = "location = '510'"
    25.         Me.DataGrid1.DataSource = dv
    26.     End Sub

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  7. #7
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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.

  8. #8
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  9. #9
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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.

  10. #10
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

  11. #11
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  12. #12
    Junior Member
    Join Date
    Aug 2002
    Location
    The 'natti
    Posts
    27
    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 & '"

  13. #13
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  14. #14
    Junior Member
    Join Date
    Aug 2002
    Location
    The 'natti
    Posts
    27
    I guess it takes a simple mind to find the simple solution?

  15. #15
    New Member
    Join Date
    Mar 2004
    Posts
    3
    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...

  16. #16
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  17. #17
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    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
  •  



Click Here to Expand Forum to Full Width