VB.NET Creating a Login System using Entity Framework 6 and SQLite


How to create a login system 
using VB.NET and SQLite (EF 6) Part 1/4


How to create a login system 
using VB.NET and SQLite (EF 6) Part 2/4


How to create a login system 
using VB.NET and SQLite (EF 6) Part 3/4


How to create a login system 
using VB.NET and SQLite (EF 6) Part 4/4



Visual Basic .NET How to Create a Login System using Entity Framework 6 and SQLite
- เขียนโปรแกรม VB .NET กับฐานข้อมูล SQLite สร้างระบบ Login โดยใช้ Entity Framework 6 หรือ EF 6


Free VB.NET Source Code by iBasskung.


Configuration File: App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
  </startup>
  <entityFramework>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
      <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite.EF6" />
      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
      <remove invariant="System.Data.SQLite" />
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="mainUsersEntities" connectionString="metadata=res://*/edmUsers.csdl|res://*/edmUsers.ssdl|res://*/edmUsers.msl;provider=System.Data.SQLite.EF6;provider connection string=&quot;data source=D:\VBSQLiteEF6LoginSystem\VBSQLiteEF6LoginSystem\bin\Debug\LoginDb.db;version=3;&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

Form: MainForm.vb

Public Class MainForm

    Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing

        Try

            Dim f As Form = New LoginForm()
            f.Show()

        Catch ex As Exception

        End Try

    End Sub

End Class

Form: LoginForm.vb

Public Class LoginForm

    Private Sub ExitButton_Click(sender As Object, e As EventArgs) Handles ExitButton.Click
        Application.ExitThread()
    End Sub

    Private Sub ShowPasswordCheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles ShowPasswordCheckBox.CheckedChanged
        PasswordTextBox.UseSystemPasswordChar = Not ShowPasswordCheckBox.Checked
    End Sub

    Private Sub LoginButton_Click(sender As Object, e As EventArgs) Handles LoginButton.Click

        Dim caption As String = "Visual Basic .NET 2021 and SQLite : iBasskung."

        If Not String.IsNullOrEmpty(Me.UsernameTextBox.Text.Trim()) And
                Not String.IsNullOrEmpty(Me.PasswordTextBox.Text.Trim()) Then

            Using db As New mainUsersEntities()

                Dim user = From u In db.Users
                           Where u.Username.Equals(Me.UsernameTextBox.Text.Trim()) And
                               u.Password.Equals(Me.PasswordTextBox.Text.Trim())
                           Select u.Username, u.Password

                If user.Count() > 0 Then

                    MessageBox.Show("Congrats! Login Successful.", caption, MessageBoxButtons.OK, MessageBoxIcon.Information)

                    'Me.UsernameTextBox.Clear()
                    'Me.PasswordTextBox.Clear()

                    ' show the main form.
                    Dim f As Form = New MainForm()
                    f.Show()

                    ' hide the login form.
                    ' Me.Hide()

                Else

                    MessageBox.Show("Invalid Username or Password.", caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

                End If

            End Using

        Else

            MessageBox.Show("Please input username and password.", caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub

        End If

    End Sub

End Class

Comments