Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. Imports System
  2. Imports System.Data
  3. Imports MySql.data.MySqlClient
  4. Imports System.Collections
  5. Imports Microsoft.VisualBasic
  6.  
  7. Public Class Login
  8. ' database variables
  9. Private DBConnection As MySqlConnection
  10. Private DBCommand As MySqlCommand
  11. Private DBReader As MySqlDataReader
  12. Private connectionString = "Database=ldawson;Data Source=localhost;User Id=ldawson;Password=ld0201213"
  13. Private SQLString As String
  14.  
  15. ' property private variables
  16. Private _username As String
  17. Private _password As String
  18. Private _access As Boolean
  19.  
  20. Private aryUserNames As ArrayList = New ArrayList()
  21. Private aryPasswords As ArrayList = New ArrayList()
  22.  
  23. ' constructor method
  24. Public Sub New()
  25. ' initialize properties
  26. _username = ""
  27. _password = ""
  28. _access = False
  29.  
  30. Try
  31. DBConnection = New MySqlConnection(connectionString)
  32. DBConnection.Open()
  33.  
  34. SQLString = "SELECT * FROM tblLogin"
  35. DBCommand = New MySqlCommand(SQLString, DBConnection)
  36. DBReader = DBCommand.ExecuteReader()
  37.  
  38. While DBReader.Read()
  39. aryUserNames.Add(DBReader("username"))
  40. aryPasswords.Add(DBReader("password"))
  41. End While
  42. ' trim off trailing elements
  43. aryUserNames.TrimToSize()
  44. aryPasswords.TrimToSize()
  45.  
  46. DBReader.Close()
  47. Finally
  48. DBConnection.Close()
  49. End Try
  50. End Sub
  51.  
  52. ' get and sets
  53. Public Property username() As String
  54. Get
  55. Return _username
  56. End Get
  57. Set(ByVal value As String)
  58. _username = value
  59. End Set
  60. End Property
  61.  
  62. Public WriteOnly Property password() As String
  63. Set(ByVal value As String)
  64. _password = value
  65. End Set
  66. End Property
  67.  
  68. Public ReadOnly Property access() As Boolean
  69. Get
  70. Return _access
  71. End Get
  72. End Property
  73.  
  74. ' public methods
  75. Public Function unlock() As Boolean
  76. Dim n As Integer
  77. ' scroll through the arrylist to see if match is found
  78. For n = 0 To (aryUserNames.Count - 1)
  79. If ((_username = aryUserNames(n)) And (_password = aryPasswords(n))) Then
  80. _access = True
  81. Exit For
  82. End If
  83. Next
  84. Return _access
  85. End Function
  86.  
  87. Public Function unlock(ByVal user As String, ByVal pass As String) As Boolean
  88. ' overloaded method
  89. _username = user
  90. _password = pass
  91. Return unlock()
  92. End Function
  93. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement