Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:09:55+00:00 2026-06-12T02:09:55+00:00

I wrote the following function to verify log in data for user, but so

  • 0

I wrote the following function to verify log in data for user, but so far its not working as it should and I am sure there is something wrong with it:

Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles button2.Click
    If loginpasswordtx.Text.Length > 1 And loginpasswordtx.Text.Length > 1 And My.Settings.SQLConnectionString.Length > 5 Then
        Try
            Dim cnn As New SqlConnection(My.Settings.SQLConnectionString)
            Dim cmd = New SqlCommand("SELECT AppUser,AppUserPass FROM OrderAppUsers WHERE AppUser=@AppUser AND AppUserPass=@AppUserPass", cnn)
            cmd.Parameters.Add(New SqlParameter("@AppUser", createuserAppUser.Text))
            cmd.Parameters.Add(New SqlParameter("@AppUserPass", MD5StringHash(loginpasswordtx.Text)))
            cnn.Open()

            Dim obj As Object = cmd.ExecuteScalar()
            If obj = Nothing Then
                MsgBox("Faild to Log in, check your log in info")
                cnn.Close()
                Return
            End If
            cnn.Close()
        Catch ex As SqlException
            MsgBox(ex.Message)
            Return
        End Try

        MsgBox("Logged in Successfully")
    End If
End Sub

All I get is a null obj even though user and pass exist in the table.

the following code is for adding new users

 Try
            Dim cnnstring As String = String.Format("Server={0};Database={1};Trusted_Connection=True;", createuserServerTx.Text, createuserDatabaseTx.Text)
            Dim cnn As New SqlConnection(cnnstring)
            Dim cmd As New SqlCommand("INSERT INTO OrderAppUsers VALUES (@AppUser, @AppUserPass)", cnn)
            cmd.Parameters.Add(New SqlParameter("@AppUser", createuserAppUser.Text))
            cmd.Parameters.Add(New SqlParameter("@AppUserPass", MD5StringHash(createuserpassword.Text)))
            cnn.Open()
            cmd.ExecuteNonQuery()
            cnn.Close()
            MsgBox("User Crated Successfully")
            LayoutControl1.Visibility = Windows.Visibility.Collapsed
            My.Settings.SQLConnectionString = cnnstring
            My.Settings.Save()
        Catch ex As SqlException
            MsgBox(ex.Message)
        End Try

and the function to generate a custom hash

 Private Function MD5StringHash(ByVal strString As String) As String
    Dim MD5 As New MD5CryptoServiceProvider
    Dim Data As Byte()
    Dim Result As Byte()
    Dim R As String = ""
    Dim Temp As String = ""

    Data = Encoding.ASCII.GetBytes(strString)
    Result = MD5.ComputeHash(Data)
    For i As Integer = 0 To Result.Length - 1
        Temp = Hex(3 * Result(i) + 1)
        If Len(Temp) = 1 Then Temp = "0" & Temp
        R += Temp
    Next
    Return R
End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:09:56+00:00Added an answer on June 12, 2026 at 2:09 am

    Try the following when adding parameter

    cmd.Parameters.AddWithValue("@AppUser", createuserAppUser.Text)
    cmd.Parameters.AddWithValue("@AppUserPass", MD5StringHash(loginpasswordtx.Text))
    

    or just stick with what you did but a little different than yours,

    cmd.Parameters.Add("@AppUser", SqlDbType.VarChar)       
    cmd.Parameters("@AppUser").Value = createuserAppUser.Text
    cmd.Parameters.Add("@AppUserPass", SqlDbType.VarChar)       
    cmd.Parameters("@AppUserPass").Value = MD5StringHash(loginpasswordtx.Text)
    

    by the way, when using ExecuteScalar() it only returns single value. So your query can be written as

    SELECT COUNT(*) 
    FROM OrderAppUsers
    WHERE AppUser=@AppUser AND AppUserPass=@AppUserPass
    

    and you can use int variable to store its value

    Dim obj As int = Cint(cmd.ExecuteScalar())
    

    so the possible values are 0 or the total number of records return.

    If obj = 0 Then
        MsgBox("Faild to Log in, check your log in info")
        '' other codes
    End If
    

    and by refractoring your code, use Using -Statement

    Using cnn As New SqlConnection(My.Settings.SQLConnectionString)
        Using cmd = New SqlCommand("SELECT COUNT(*) FROM OrderAppUsers WHERE AppUser=@AppUser AND AppUserPass=@AppUserPass", cnn)
            cmd.Parameters.AddWithValue("@AppUser", createuserAppUser.Text)
            cmd.Parameters.AddWithValue("@AppUserPass", MD5StringHash(loginpasswordtx.Text))
            cmd.CommandType = CommandType.Text
            Try
                cnn.Open()
                Dim obj As int = Cint(cmd.ExecuteScalar())
                If obj = 0 Then
                    MsgBox("Faild to Log in, check your log in info")
                Else
                     MsgBox("Logged in Successfully")
                End If
            Catch(ex As SqlException)
                 MsgBox(ex.Message.ToString())
            End Try
        End Using
    End Using
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote the following function to view data in a grid from F# interactive:
I wrote following function void validateUser(void) { string uName; string uPassword; char c; map
I wrote the following function in haskell, as it will enumerate every integer: integers
I wrote the following: Object.prototype.length = function(){ var count = -1; for(var i in
I want to call the Sleep function on ASM. So I wrote the following:
Is there a better way to write the following function? Having the '#' +
I wrote the following function to convert a time in milliseconds to a string
I wrote the following function to split the given full path into directory, filename
I created a class A and wrote the following function foo() class A {
I wrote the following function to check if my HTML5 openDatabase table is filled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.