Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. Imports MySql.Data.MySqlClient
  2.  
  3. Imports System.Security
  4.  
  5. Imports System.Security.Cryptography
  6.  
  7.  
  8. Public Class user
  9.  
  10. Public Function AES_Encrypt(ByVal input As String, ByVal pass As String) As String
  11. Dim AES As New System.Security.Cryptography.RijndaelManaged
  12. Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
  13. Dim encrypted As String = ""
  14. Try
  15. Dim hash(31) As Byte
  16. Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))
  17. Array.Copy(temp, 0, hash, 0, 16)
  18. Array.Copy(temp, 0, hash, 15, 16)
  19. AES.Key = hash
  20. AES.Mode = Security.Cryptography.CipherMode.ECB
  21. Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateEncryptor
  22. Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(input)
  23. encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
  24. Return encrypted
  25.  
  26. Catch ex As Exception
  27.  
  28. End Try
  29. End Function
  30.  
  31. Private Sub BCreateAcount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BCreateAcount.Click
  32. Dim conn As MySqlConnection
  33. conn = New MySqlConnection
  34.  
  35. conn.ConnectionString = "server = localhost;username= root;password= a;database= database"
  36.  
  37. Try
  38. conn.Open()
  39. Catch mali As MySqlException
  40. MsgBox("connot establish connection")
  41. End Try
  42. Dim myCommand As New MySqlCommand
  43. Dim myReader As MySqlDataReader
  44.  
  45.  
  46. myCommand.Connection = conn
  47. myCommand.CommandText = "insert into user values('" + txtUserName.Text + "','" + txtNewPassword.Text + "')"
  48. Call calldaw()
  49.  
  50.  
  51. If txtUserName.Text = "" Or txtNewPassword.Text = "" Or txtConfirmPassword.Text = "" Then
  52. MsgBox("Please enter username and password", MsgBoxStyle.Information, "Inventory System")
  53. ElseIf txtConfirmPassword.Text = txtNewPassword.Text Then
  54.  
  55. MsgBox("Account Created", MsgBoxStyle.Information, "Inventory System")
  56. myReader = myCommand.ExecuteReader()
  57. txtUserName.Text = ""
  58. txtNewPassword.Text = ""
  59. txtConfirmPassword.Text = ""
  60.  
  61. Else
  62. MsgBox("Password did not match", MsgBoxStyle.Critical, "Inventory System")
  63. txtConfirmPassword.Text = ""
  64. txtNewPassword.Text = ""
  65. txtUserName.Text = ""
  66. End If
  67.  
  68. End Sub
  69. Private Sub calldaw()
  70. Dim conn As MySqlConnection
  71. conn = New MySqlConnection
  72.  
  73. conn.ConnectionString = "server = localhost;username= root;password= a;database= database"
  74.  
  75. Try
  76. conn.Open()
  77. Catch mali As MySqlException
  78. MsgBox("connot establish connection")
  79. End Try
  80.  
  81. Dim myData As MySqlDataAdapter
  82. Dim reason As String = " Create Account "
  83. Dim tao As String = "admin"
  84.  
  85. myData = New MySqlDataAdapter
  86.  
  87. Dim sqlsql = "insert into daily_log values('" + tao + "','" + Date1.Text + "','" + reason + "','" + Time1.Text + "')"
  88. Dim ssql = "Select * from user"
  89.  
  90. Dim myCommand As New MySqlCommand
  91. myCommand.Connection = conn
  92. myCommand.CommandText = sqlsql
  93.  
  94. Dim myReader As MySqlDataReader
  95. myReader = myCommand.ExecuteReader
  96.  
  97. End Sub
  98.  
  99. Private Sub BBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BBack.Click
  100. Me.Close()
  101. End Sub
  102.  
  103. Private Sub user_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  104. Timer1.Enabled = True
  105. End Sub
  106.  
  107. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  108. Date1.Text = Date.Today.Date
  109. Dim Date2 As Date = Date1.Text
  110. Date1.Text = Format(Date2, "yyyy-MM-dd")
  111. Time1.Text = TimeOfDay
  112. End Sub
  113.  
  114. End Class
  115.  
  116. Dim myCommand As New MySqlCommand
  117. Dim myReader As MySqlDataReader
  118.  
  119.  
  120. myCommand.Connection = conn
  121. myCommand.CommandText = "insert into user values('" + txtUserName.Text + "','" + AES_Encrypt(txtNewPassword.Text,txtNewPassword.Text) + "')"
  122. Call calldaw()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement