Senin, 29 Juni 2015

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


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 MySql.Data.MySqlClient;

namespace Project
{
public partial class Form_Mysql_Login : Form
{
public Form_Mysql_Login()
{
InitializeComponent();
}
MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;Initial Catalog='test';username=root;password=");
MySqlDataAdapter adapter;
DataTable table = new DataTable();
private void button_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 = "Invalid Username Or Password";
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();
}
}
}

// hide the panel message
private void button_Ok_Click(object sender, EventArgs e)
{
timer2.Start();
}

// Show And Hide Password
private void checkBox_Show_Password_CheckedChanged(object sender, EventArgs e)
{
if (checkBox_Show_Password.Checked)
{
textBox_Password.UseSystemPasswordChar = false;
}

else
{
textBox_Password.UseSystemPasswordChar = true;
}
}
}
}
///////////////OUTPUT:

c# login form with mysql database
Invalid Username Or Password
c# login window with mysql database
Login Successfully
Other Posts:


Connect C# To MySQL And Display Data



Create Login Form In C# With Access Database


Bagikan

Jangan lewatkan

C# - How To Create Login Form In C# With MySQL Database
4/ 5
Oleh

Subscribe via email

Suka dengan artikel di atas? Tambahkan email Anda untuk berlangganan.