Step 01: Desing Form Sign In

Tools for using design:

  • Panel
  • Lable
  • TextBox
  • CheckBox
  • Button

Color code: #F4B400, #A0A0A0, #FFFFFF

Step 02: Desing Form Registration

Tools for using design:

  • Panel
  • Lable
  • TextBox
  • CheckBox
  • Button

Step 03: Create access database file

Design DataBase on Access 2019:

  • Create table name "userDB"
  • Column 01 "username"
  • Column 02 "password"
  • save table to location source on "../bin/Debug/userDB.mdb"

Note: Save file DataBase on Access to extensions ".mdb"

Step 04: Show Password

CheckBox name "chShowPassword".

Source Code
private void chShowPassword_CheckedChanged(object sender, EventArgs e)
        {
            if (chShowPassword.Checked)
            {
                txtPassword.PasswordChar = '\0';
            }
            else
            {
                txtPassword.PasswordChar = '•';
            }
        }

Note: Copy "•" to past on properties PasswordChar for tex box password.

Step 05: Connect Form to Access Database

Using System.

Source Code
using System.Data.OleDb;

Connection code.

Source Code
OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=db.mdb");
        OleDbCommand cmd = new OleDbCommand();
        OleDbDataAdapter da = new OleDbDataAdapter();

Step 06: Button Sign Up

Button name "btnSignUp".

Source Code
private void btnSignUp_Click(object sender, EventArgs e)
        {
            if (txtUser.Text == "" && txtPass.Text == "" && txtConfirm.Text == "")
            {
                MessageBox.Show("Username and Password fields are empty", "Sign Up Field", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
            else if (txtPass.Text == txtConfirm.Text)
            {
                con.Open();
                string signup = "INSERT INTO userDB VALUES ('" + txtUser.Text + "', '"+ txtPass.Text +"')";
                cmd = new OleDbCommand(signup, con);
                cmd.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("Your Account Created Successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Passwords dose not match, Please Re-enter.", "Register", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPass.Text = "";
                txtConfirm.Text = "";
                txtPass.Focus();
            }

            txtUser.Text = "";
            txtPass.Text = "";
            txtConfirm.Text = "";
            new Login().Show();
            this.Hide();
        }

Lable Switch Sign In form to Sign Up

Source Code
private void lbLogin_Click(object sender, EventArgs e)
        {
            new Login().Show();
            this.Hide();
        }

Step 07: Button Sign In

Button name "btnSignIn".

Source Code
private void btnSignIn_Click(object sender, EventArgs e)
        {
            con.Open();
            string login = "SELECT * FROM userDB WHERE username = '"+txtUser.Text+"' and password = '"+txtPassword.Text+"'";
            cmd = new OleDbCommand(login, con);
            OleDbDataReader dr = cmd.ExecuteReader();
            
            if (dr.Read() == true)
            {
                new Dashboard().Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("Invalide Username or Password, Please try again.", "Login Field", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtUser.Text = "";
                txtPassword.Text = "";
                txtUser.Focus();
            }
            con.Close();
        }