title: VB.NET log in form using MySQL database
body: <p>Can someone help me with the following please.</p>
  
  <p>I have created a database called dbhr and a table in it called user with two fields 'username' and 'password' having VARCHAR data type.
  I have a log in form with two textboxes (tbxUsername,tbxPassword) and an OK button. I have connected my database to authenticate the username and password. But it always give me wrong password message. I don't know where I went wrong.
  Please help.</p>
  
  <p>I use MySQL Workbench 6.1</p>
  
  <p>Thanks in advance.</p>
  
  <p>Here is the VB.NET log in button code.</p>
  
  <pre class="lang-vb prettyprint-override"><code>Imports MySql.Data.MySqlClient
  
  Public Class Login
  
      Dim mydbcon As MySqlConnection
      Dim COMMAND As MySqlCommand
  
      ' TODO: Insert code to perform custom authentication using the provided username and password 
      ' (See http://go.microsoft.com/fwlink/?LinkId=35339).  
      ' The custom principal can then be attached to the current thread's principal as follows: 
      '     My.User.CurrentPrincipal = CustomPrincipal
      ' where CustomPrincipal is the IPrincipal implementation used to perform authentication. 
      ' Subsequently, My.User will return identity information encapsulated in the CustomPrincipal object
      ' such as the username, display name, etc.
  
      Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
          mydbcon = New MySqlConnection
          mydbcon.ConnectionString = "server=localhost;userid=root;password=rootword;database=hrdb"
          Dim reader As MySqlDataReader
  
          Try
              mydbcon.Open()
              Dim Query As String
              Query = "select * from user where username= ' " &amp; tbxUsername.Text &amp; "' and password= ' " &amp; tbxPassword.Text &amp; "' "
              COMMAND = New MySqlCommand(Query, mydbcon)
              reader = COMMAND.ExecuteReader
  
              Dim count As Integer
              count = 0
              While reader.Read
                  count = count + 1
  
              End While
  
              If count = 1 Then
                  MessageBox.Show("Username and password are correct")
              ElseIf count &gt; 1 Then
                  MessageBox.Show("Username and password are duplicate")
              Else
                  MessageBox.Show("Username and password are wrong")
              End If
              mydbcon.Close()
          Catch ex As MySqlException
              MessageBox.Show(ex.Message)
          Finally
              mydbcon.Dispose()
          End Try
  
      End Sub
  </code></pre>
  
  <p>Please click the following links to see the database table records and data types.</p>
  
  <p>Click <a href="https://0466f663-a-62cb3a1a-s-sites.googlegroups.com/site/ssdfdsfdsfdsfdsf/home/Database%20table%20with%20records%20and%20log%20in%20result.jpg?attachauth=ANoY7cpxgiS2sYPvcmMHKeiPhoXRjBZmKxJRddHzAx1rZe9bfwyejD5rDlQEIRPYxjWBwUHUEdTaVEeNs4Hm7vtgmq6iDpMAtpiVCQZu_BRKkcOyU-dal57zzewAbDYKY1F4GJ5Jj-mZljzcniXeGDEEts1McopzhAYtHu7jxvmxPJosu-OL9MmTIZLHcocw7-ZoXCLsBi5X5Uz27kdDdP6U-fetnOgG0i8l2PzJe4MgXOwmuuua7Lb3qo3VnfPC9p6ZH-OXgtb0vQu-JMmb-lhzLMYOukMnwg%3D%3D&amp;attredirects=0" rel="nofollow" title="Screenshot of Database table field type, table records and login button result">here</a>!</p>