Advertisement
Guest User

Untitled

a guest
Jan 27th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. Private Sub button4_Click(sender As Object, e As EventArgs) Handles button4.Click 'When the login button is clicked the data inside of the username and password textbox is checked against the database
  2. Dim cs As String = "server=95.128.129.130; user id=dsfcuser5; password=!ANeusdj2DVCb!; database=dbdsfc5;" 'Server details, username and password
  3. Dim conn As New MySqlConnection(cs)
  4. Try
  5. conn.Open() 'Opens the mysql connection that is declared above
  6. Dim stm As String = "SELECT * FROM dbdsfc5.accounts WHERE username='" & username.Text + "' AND password='" & encryption.hashString(password.Text) & "' " 'sql command is declared as stm variable
  7. Dim cmd As MySqlCommand = New MySqlCommand(stm, conn)
  8. Dim reader As MySqlDataReader = cmd.ExecuteReader()
  9. Dim count As Integer = 0
  10. While reader.Read() 'while the reader is pulling data
  11. count = count + 1 'increment the count
  12. End While
  13. If count = 1 Then 'if the count is one it has sucessfully pulled corrosponding data from the database
  14. MessageBox.Show("Sucess") 'display sucess
  15. userID = reader.GetString(0)
  16. panel2.Hide() 'Hide the login form if the login is correct
  17. panel1.Show() 'Show the main UI if the login is correct
  18. FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle 'Becomes a sizeable window
  19. Me.ShowIcon = True
  20.  
  21. Me.Width = 754 'change the size of the form so that
  22. Me.Height = 583
  23. Me.MaximumSize = New Size(677, 525)
  24. Me.MinimumSize = New Size(677, 525)
  25.  
  26.  
  27.  
  28. 'Form2 location and show
  29. Dim frm1Width As Integer = Me.Width
  30. If Form2.Visible = False Then
  31. Form2.Show()
  32. 'set form2's new location beside form1 by adding frm1's width to its current X Position and just use the frm1's Y Position to level both forms
  33. Form2.Location = New Point(Me.Location.X + frm1Width, Me.Location.Y)
  34. Else
  35. Form2.Hide()
  36. End If
  37.  
  38.  
  39.  
  40.  
  41. getSug() 'gets sugars from the data table in the database
  42. Stats() 'calculates stats from the requested data
  43. ElseIf count > 1 Then
  44. MessageBox.Show("Duplicate users") 'if there is already an entry
  45. Else
  46. MessageBox.Show("Incorrect login: querey failed")
  47. End If
  48. reader.Close() 'close the reader which requested the data for the login
  49. Catch ex As MySqlException
  50. Console.WriteLine("Error: " & ex.ToString())
  51. Finally
  52. conn.Close()
  53. End Try
  54.  
  55.  
  56.  
  57.  
  58. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement