Login Form With Remember - Biometric Attendance USB System C#|VS2022|SQL2022

To create a new SQL Server database and table on a server named Vich-PC\SQLEXPESS, you can use the following SQL commands:

CREATE DATABASE SimpleReportAttendance;
GO

USE SimpleReportAttendance;
GO

CREATE TABLE Login (
    -- Add your column definitions here
);
GO

This title refers to a login form that includes a “Remember Me” feature, which allows users to save their login credentials for future use. The form is part of a biometric attendance system that uses a USB device to record employee attendance. The system is developed using C# programming language in Visual Studio 2022 and uses SQL Server 2022 for data storage and management.


This code appears to be part of a login form for a biometric attendance system. It contains three event handlers for the btLogin button click, the cbRemember checkbox checked change, and the Login form load events.


The btLogin_Click event handler is executed when the user clicks on the btLogin button. It attempts to establish a connection to a SQL Server database using a connection string. Then it creates a SqlDataAdapter object with a SQL query that selects the count of rows from the Login table where the Username and Password columns match the text entered by the user in the txtUsername and txtPassword text boxes. The results of this query are stored in a DataTable object. If the count of rows returned by the query is 1, then the login is successful and the current form is hidden while a new instance of the Main form is shown. Otherwise, a message box is displayed to inform the user that their username or password is invalid.


The cbRemember_CheckedChanged event handler is executed when the user checks or unchecks the cbRemember checkbox. If the checkbox is checked, then the text entered by the user in the txtUsername and txtPassword text boxes is saved to the application’s settings. If it’s unchecked, then these settings are cleared.


The Login_Load event handler is executed when the login form is loaded. It checks if there are saved values for the username and password in the application’s settings. If there are, then these values are used to populate the text in the txtUsername and txtPassword text boxes.


using System;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;

namespace BiometricRecordUSBReport
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void btLogin_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection(@"Data Source=VICH-PC\SQLEXPRESS;Initial Catalog=BiometricUSB;Integrated Security=true");
                SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) From Login Where Username='" + txtUsername.Text + "'And Password='" + txtPassword.Text + "'", con);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                if (dt.Rows[0][0].ToString() == "1")
                {
                    this.Hide();
                    Main ss = new Main();
                    ss.Show();
                }
                else
                {
                    MessageBox.Show("Invalid username or password");
                }
            }catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

        }

        private void cbRemember_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (cbRemember.Checked)
                {
                    Properties.Settings.Default.Username = txtUsername.Text;
                    Properties.Settings.Default.Password = txtPassword.Text;
                    Properties.Settings.Default.Save();
                }
                else
                {
                    Properties.Settings.Default.Username = "";
                    Properties.Settings.Default.Password = "";
                    Properties.Settings.Default.Save();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        private void Login_Load(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.Username != String.Empty)
            {
                txtUsername.Text = Properties.Settings.Default.Username;
                txtPassword.Text = Properties.Settings.Default.Password;
            }
        }
    }
}

This is video tutorial on YouTube : 

Post a Comment

Previous Post Next Post