Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System
- Imports System.Data
- Imports MySql.data.MySqlClient
- Imports System.Collections
- Imports Microsoft.VisualBasic
- Public Class Login
- ' database variables
- Private DBConnection As MySqlConnection
- Private DBCommand As MySqlCommand
- Private DBReader As MySqlDataReader
- Private connectionString = "Database=ldawson;Data Source=localhost;User Id=ldawson;Password=ld0201213"
- Private SQLString As String
- ' property private variables
- Private _username As String
- Private _password As String
- Private _access As Boolean
- Private aryUserNames As ArrayList = New ArrayList()
- Private aryPasswords As ArrayList = New ArrayList()
- ' constructor method
- Public Sub New()
- ' initialize properties
- _username = ""
- _password = ""
- _access = False
- Try
- DBConnection = New MySqlConnection(connectionString)
- DBConnection.Open()
- SQLString = "SELECT * FROM tblLogin"
- DBCommand = New MySqlCommand(SQLString, DBConnection)
- DBReader = DBCommand.ExecuteReader()
- While DBReader.Read()
- aryUserNames.Add(DBReader("username"))
- aryPasswords.Add(DBReader("password"))
- End While
- ' trim off trailing elements
- aryUserNames.TrimToSize()
- aryPasswords.TrimToSize()
- DBReader.Close()
- Finally
- DBConnection.Close()
- End Try
- End Sub
- ' get and sets
- Public Property username() As String
- Get
- Return _username
- End Get
- Set(ByVal value As String)
- _username = value
- End Set
- End Property
- Public WriteOnly Property password() As String
- Set(ByVal value As String)
- _password = value
- End Set
- End Property
- Public ReadOnly Property access() As Boolean
- Get
- Return _access
- End Get
- End Property
- ' public methods
- Public Function unlock() As Boolean
- Dim n As Integer
- ' scroll through the arrylist to see if match is found
- For n = 0 To (aryUserNames.Count - 1)
- If ((_username = aryUserNames(n)) And (_password = aryPasswords(n))) Then
- _access = True
- Exit For
- End If
- Next
- Return _access
- End Function
- Public Function unlock(ByVal user As String, ByVal pass As String) As Boolean
- ' overloaded method
- _username = user
- _password = pass
- Return unlock()
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement