Results 1 to 23 of 23

Thread: Validate Credentials Against User Record in Database

Threaded View

  1. #1

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Validate Credentials Against User Record in Database

    C# version here.

    VB.NET Code:
    1. Dim connection As New SqlConnection("connection string here")
    2.  
    3. 'Get the count of the records with matching user ID and password.
    4. Dim command As New SqlCommand("SELECT COUNT(*) FROM User WHERE UserID = @UserID AND Password = @Password", _
    5.                               connection)
    6.  
    7. 'Add the parameters.  Values might come from TextBoxes or wherever.
    8. With command.Parameters
    9.     .AddWithValue("@UserID", userID)
    10.     .AddWithValue("@Password", password)
    11. End With
    12.  
    13. connection.Open()
    14.  
    15. 'Execute the query.
    16. If CInt(command.ExecuteScalar()) = 0 Then
    17.     'Zero matching records means a failed login.
    18. Else
    19.     'The specified credentials do match a record so the login succeeds.
    20. End If
    21.  
    22. connection.Close()
    Last edited by jmcilhinney; Nov 23rd, 2008 at 06:39 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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