Affichage des articles dont le libellé est How To Create Login Form In C#. Afficher tous les articles
Affichage des articles dont le libellé est How To Create Login Form In C#. Afficher tous les articles

C# - How To Create Login Form In C# With MySQL Database

C# - How To Create Login Window In C# With MySQL Database

                                                                                                                                         

In This C# Tutorial We Will See How To Make A Login Form Using CSharp Programming Language And MySQL Database.

                                                      
                                                                      Part 1


Part 2

Source Code :

using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Csharp_And_MySQL
{
    public partial class Login_Form_2 : Form
    {
        public Login_Form_2()
        {
            InitializeComponent();
        }

        MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;Initial Catalog='test';username=root;password=");

        MySqlDataAdapter adapter;

        DataTable table = new DataTable();

        private void BTN_Login_Click(object sender, EventArgs e)
        {
            adapter = new MySqlDataAdapter("SELECT `username`, `password` FROM `users` WHERE `username` = '" + textBox_username.Text + "' AND `password` = '" + textBox_password.Text + "'", connection);
            adapter.Fill(table);

            if(table.Rows.Count <= 0)
            {
                panel1.Height = 0;
                label_Message.ForeColor = Color.Red;
                label_Message.Text = "Username Or Password Are Invalid";
                timer1.Start();
            }
            else
            {
                panel1.Height = 0;
                label_Message.ForeColor = Color.Green;
                label_Message.Text = "Login Successfully";
                timer1.Start();
            }

            table.Clear();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if(panel1.Height != 100)
            {
                panel1.Height = panel1.Height + 5;
                if(panel1.Height == 100)
                {
                    timer1.Stop();
                }
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            if (panel1.Height != 0)
            {
                panel1.Height = panel1.Height - 5;
                if (panel1.Height == 0)
                {
                    timer2.Stop();
                }
            }
        }

        private void BTN_OK_Click(object sender, EventArgs e)
        {
            timer2.Start();
        }

        private void checkBox_ShowPass_CheckedChanged(object sender, EventArgs e)
        {
            if(checkBox_ShowPass.Checked)
            {
                textBox_password.UseSystemPasswordChar = true;
            }
            else
            {
                textBox_password.UseSystemPasswordChar = false;
            }
        }
       
    }
}

=> OutPut :

c# login window
Login Failed

c# login window
 Login Successfully




C# - How To Create Login Form In C# With Access Database [with source code]

C# - How To Create Login Form In C# With Access Database [with source code]

                                                                                                                                         

In This C# Tutorial We Will See How To Make A Login Form Using CSharp Programming Language And Access Database.



Project Source Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
 
namespace LoginPrj
{
    public partial class TestForm : Form
    {
        OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Documents\DataBase1.accdb");
        OleDbDataAdapter da;
        DataTable dt = new DataTable();
        public TestForm()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            da = new OleDbDataAdapter("select * from MyTab where Email='"+textBox1.Text+"' and Password='"+textBox2.Text+"'",cn);
            da.Fill(dt);
            if (dt.Rows.Count <= 0)
            {
                if(panel1.Height == 0)
                {
                    label1.Text = "Email Or Passwor are Invalide Please try again";
                    timer1.Start();
                }
                else if (panel1.Height == 100)
                {
                    timer2.Start();
                    label1.Text = "";
                }
            }
            else if (dt.Rows.Count > 0)
            {
                if (panel1.Height == 0)
                {
                    label1.Text = "Login Succsufully";
                    timer1.Start();
                }
                else if (panel1.Height == 100)
                {
                    timer2.Start();
                    label1.Text = "";
                }
            }
 
            dt.Clear();
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            if(panel1.Height != 100)
            {
                panel1.Height +=5;
                if(panel1.Height == 100)
                {
                    timer1.Stop();
                }
            }
        }
 
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (panel1.Height != 0)
            {
                panel1.Height -= 5;
                if (panel1.Height == 0)
                {
                    timer2.Stop();
                }
            }
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            timer2.Start();
        }
    }
}

////////////////////////////////END
Other Login Form Post:
Create Login Form In C# With MySQL Database