Jump to content

Login and Register Forms, using database

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Zvone

Zvone

    Newbie

  • Members
  • Pip
  • 3 posts
You can register by entering a new username and password and then logged in.
Your data are saved in a SQL Server Express 2008 R2 database.

'// Login Form


Imports System.Data.SqlClient

Imports System.Media


Public Class Login

    Dim path = System.Windows.Forms.Application.StartupPath

    Dim LogOnsound As String

    Dim MyPlayer As New SoundPlayer()


    Dim sqlLink As SqlConnection


    Private Sub Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        LogOnsound = "\LogOn.wav"

        sqlLink = New SqlConnection()

        sqlLink.ConnectionString = "Data Source=ZVONKO-PC\SQLEXPRESS;Initial Catalog=LoginSystem;User ID=Something;Password=Something" '//Put your data

    End Sub


    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Register.Show()

        Me.Hide()

    End Sub


    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click

        Me.Close()

    End Sub


    Private Sub btnLogIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogIn.Click

        Try

            sqlLink.Open()

            Dim sqlOrder As New SqlCommand()

            sqlOrder.Connection = sqlLink

            sqlOrder.CommandText = "SELECT * FROM User_Data WHERE Username ='" & txtUsername.Text & "' AND Password ='" & txtPassword.Text & "' "

            Dim sqlReading As SqlDataReader = sqlOrder.ExecuteReader()

            If (sqlReading.Read() = True) Then

                MyPlayer.SoundLocation = path & LogOnsound

                MyPlayer.Play()

                FormProject.Show()

                Me.Hide()

            ElseIf txtUsername.Text = "" Or txtPassword.Text = "" Then

                Beep()

                MsgBox("Incomplete details !")

            Else

                Beep()

                MsgBox("Incorrect details !")

            End If

            sqlReading.Close()

        Catch ex As Exception

            MsgBox("An error occurred: " & ex.Message)

        Finally

            sqlLink.Close()

        End Try

    End Sub

End Class



'// Register Form


Imports System.Data.SqlClient


Public Class Register

    Dim sqlLink As SqlConnection


    Private Sub Register_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        sqlLink = New SqlConnection()

        sqlLink.ConnectionString = "Data Source=ZVONKO-PC\SQLEXPRESS;Initial Catalog=LoginSystem;User ID=Something;Password=Something"  '//Put your data

    End Sub


    Private Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click

        Try

            sqlLink.Open()

            If txtUsername.Text = "" Then

                MsgBox("You did not enter a Username !")

                sqlLink.Close()

                Return

            ElseIf txtPassword.Text = "" Then

                MsgBox("You did not enter a Password !")

                sqlLink.Close()

                Return

            ElseIf txtPassword.Text <> txtRePassword.Text Then

                MsgBox("Passwords do not match !")

                sqlLink.Close()

                Return

            Else

                MsgBox("You have successfully registered, you can log in now !")

            End If

            Dim sqlOrder As New SqlCommand()

            sqlOrder.Connection = sqlLink

            sqlOrder.CommandText = "INSERT INTO User_Data(Username,Password) " &

                                   "VALUES('" & txtUsername.Text & "','" & txtPassword.Text & "')"

            sqlOrder.ExecuteNonQuery()

        Catch EX As Exception

            MsgBox("An error occurred: " & EX.Message)

        Finally

            sqlLink.Close()

        End Try

        Me.Close()

        Login.Show()

    End Sub


    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click

        Me.Close()

        Login.Close()

    End Sub

End Class



'// Project Form


Imports System.Media


Public Class FormProject

    Dim path = System.Windows.Forms.Application.StartupPath

    Dim LogOnsound As String

    Dim MyPlayer As New SoundPlayer()


    Private Sub FormProject_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        LogOnsound = "\LogOff.wav"

    End Sub


    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

        MyPlayer.SoundLocation = path & LogOnsound

        MyPlayer.Play()

        Login.Close()

        Me.Close()

    End Sub

End Class


In WinRAR archive is a complete project :)

Attached Files



#2
FNSQ

FNSQ

    Newbie

  • Members
  • Pip
  • 1 posts
thank you very musch

#3
IsItVoid

IsItVoid

    Newbie

  • Members
  • Pip
  • 2 posts
Looks Like some good work :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users