I have created a simple log on screen that checks the local database if the username and password exist and to add them to the database if it doesn't exist.
On the Login window I have a Label that I would like to equal the user who has logged on.
Here is my code.....
On the Login window I have a Label that I would like to equal the user who has logged on.
Here is my code.....
Code:
Public Class loginWindow
Private Users As New UsersDataSetTableAdapters.CredentialsTableAdapter
Private DataSet As New UsersDataSet
Private Sub Register(ByVal Username As String, ByVal Password As String)
Dim Row As UsersDataSet.CredentialsRow = DataSet.Credentials.FindByUsername(Username)
If Row Is Nothing Then
DataSet.Credentials.AddCredentialsRow(Username, Password)
Users.Update(DataSet)
MessageBox.Show("Account Created")
Else
MessageBox.Show("Username not available please choose another!")
End If
End Sub
Private Sub Login(ByVal Username As String, ByVal Password As String)
Dim Row As UsersDataSet.CredentialsRow = DataSet.Credentials.FindByUsername(Username)
If Not Row Is Nothing AndAlso Row.Password = Password Then
MessageBox.Show("Correct Credentials Logging in!")
Else
MessageBox.Show("Invalid Credentials")
End If
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Users.Fill(DataSet.Credentials())
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles LoginButton.Click
Label1.Text =
Call Login(UsernameTextBox.Text, LoginTextBox.Text)
End Sub
Private Sub RegistrationButton_Click(sender As System.Object, e As System.EventArgs) Handles RegistrationButton.Click
Call Register(UsernameTextBox.Text, LoginTextBox.Text)
End Sub
Private Sub LoginTextBox_Click(sender As Object, e As System.EventArgs) Handles LoginTextBox.Click
LoginTextBox.Text = ""
End Sub
Private Sub UsernameTextBox_Click(sender As Object, e As System.EventArgs) Handles UsernameTextBox.Click
UsernameTextBox.Text = ""
End Sub
End Class