Guest User

Untitled

a guest
Jan 18th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles button2.Click
  2. If loginpasswordtx.Text.Length > 1 And loginpasswordtx.Text.Length > 1 And My.Settings.SQLConnectionString.Length > 5 Then
  3. Try
  4. Dim cnn As New SqlConnection(My.Settings.SQLConnectionString)
  5. Dim cmd = New SqlCommand("SELECT AppUser,AppUserPass FROM OrderAppUsers WHERE AppUser=@AppUser AND AppUserPass=@AppUserPass", cnn)
  6. cmd.Parameters.Add(New SqlParameter("@AppUser", createuserAppUser.Text))
  7. cmd.Parameters.Add(New SqlParameter("@AppUserPass", MD5StringHash(loginpasswordtx.Text)))
  8. cnn.Open()
  9.  
  10. Dim obj As Object = cmd.ExecuteScalar()
  11. If obj = Nothing Then
  12. MsgBox("Faild to Log in, check your log in info")
  13. cnn.Close()
  14. Return
  15. End If
  16. cnn.Close()
  17. Catch ex As SqlException
  18. MsgBox(ex.Message)
  19. Return
  20. End Try
  21.  
  22. MsgBox("Logged in Successfully")
  23. End If
  24. End Sub
  25.  
  26. Try
  27. Dim cnnstring As String = String.Format("Server={0};Database={1};Trusted_Connection=True;", createuserServerTx.Text, createuserDatabaseTx.Text)
  28. Dim cnn As New SqlConnection(cnnstring)
  29. Dim cmd As New SqlCommand("INSERT INTO OrderAppUsers VALUES (@AppUser, @AppUserPass)", cnn)
  30. cmd.Parameters.Add(New SqlParameter("@AppUser", createuserAppUser.Text))
  31. cmd.Parameters.Add(New SqlParameter("@AppUserPass", MD5StringHash(createuserpassword.Text)))
  32. cnn.Open()
  33. cmd.ExecuteNonQuery()
  34. cnn.Close()
  35. MsgBox("User Crated Successfully")
  36. LayoutControl1.Visibility = Windows.Visibility.Collapsed
  37. My.Settings.SQLConnectionString = cnnstring
  38. My.Settings.Save()
  39. Catch ex As SqlException
  40. MsgBox(ex.Message)
  41. End Try
  42.  
  43. Private Function MD5StringHash(ByVal strString As String) As String
  44. Dim MD5 As New MD5CryptoServiceProvider
  45. Dim Data As Byte()
  46. Dim Result As Byte()
  47. Dim R As String = ""
  48. Dim Temp As String = ""
  49.  
  50. Data = Encoding.ASCII.GetBytes(strString)
  51. Result = MD5.ComputeHash(Data)
  52. For i As Integer = 0 To Result.Length - 1
  53. Temp = Hex(3 * Result(i) + 1)
  54. If Len(Temp) = 1 Then Temp = "0" & Temp
  55. R += Temp
  56. Next
  57. Return R
  58. End Function
  59.  
  60. cmd.Parameters.AddWithValue("@AppUser", createuserAppUser.Text)
  61. cmd.Parameters.AddWithValue("@AppUserPass", MD5StringHash(loginpasswordtx.Text))
  62.  
  63. cmd.Parameters.Add("@AppUser", SqlDbType.VarChar)
  64. cmd.Parameters("@AppUser").Value = createuserAppUser.Text
  65. cmd.Parameters.Add("@AppUserPass", SqlDbType.VarChar)
  66. cmd.Parameters("@AppUserPass").Value = MD5StringHash(loginpasswordtx.Text)
  67.  
  68. SELECT COUNT(*)
  69. FROM OrderAppUsers
  70. WHERE AppUser=@AppUser AND AppUserPass=@AppUserPass
  71.  
  72. Dim obj As int = Cint(cmd.ExecuteScalar())
  73.  
  74. If obj = 0 Then
  75. MsgBox("Faild to Log in, check your log in info")
  76. '' other codes
  77. End If
  78.  
  79. Using cnn As New SqlConnection(My.Settings.SQLConnectionString)
  80. Using cmd = New SqlCommand("SELECT COUNT(*) FROM OrderAppUsers WHERE AppUser=@AppUser AND AppUserPass=@AppUserPass", cnn)
  81. cmd.Parameters.AddWithValue("@AppUser", createuserAppUser.Text)
  82. cmd.Parameters.AddWithValue("@AppUserPass", MD5StringHash(loginpasswordtx.Text))
  83. cmd.CommandType = CommandType.Text
  84. Try
  85. cnn.Open()
  86. Dim obj As int = Cint(cmd.ExecuteScalar())
  87. If obj = 0 Then
  88. MsgBox("Faild to Log in, check your log in info")
  89. Else
  90. MsgBox("Logged in Successfully")
  91. End If
  92. Catch(ex As SqlException)
  93. MsgBox(ex.Message.ToString())
  94. End Try
  95. End Using
  96. End Using
Add Comment
Please, Sign In to add comment