Tutorials
Tutorials
Downloads
C#, JAVA,PHP,
Programming ,Source Code
▶ Download Projects Source Code
Download now >>
PROJECTS
C#
JAVA
PHP
VB.NET
JAVASCRIPT
DOWNLOADS
Search... ?
➜ Download 10 Java Projects Code ➜ Download 7 C# Projects Code ➜ Download 7 VB.Net Projects
Code ➜ Download 5 PHP Projects Code
C# Login And Register Form With MySQL
c# C# Login And Register Form With MySQL c# login form c# signup form Design
Login Form Design Register Form How To Make Login And Signup Form In
C# login register
In This C# Tutorial We Will See How To Design a Login & Signup Form and Connect Those
Two Forms With MySQL Database To Allow The Users To Create Their Account or To Access
The Application Using C# Windows Form and Visual Studio Editor .
// ------ First We Need To Create a Class To Connect Our Application With The MySQL
Database
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
namespace Csharp_Login_And_Register
{
/*
* we need to download the mysql connector
* add the connector to our project
* ( watch the video to see how )
* create a connection now with mysql
* open xampp and start mysql & apache
* go to phpmyadmin and create the users database
*/
class DB
{
// the connection
private MySqlConnection connection = new
MySqlConnection("server=localhost;port=3306;username=root;password=;database=csharp_
users_db");
// ------ After Creating The Connection Class, Now We Need To Build a Register Form To
Allow Users To Create Their Account
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;
using MySql.Data.MySqlClient;
namespace Csharp_Login_And_Register
{
public partial class RegisterForm : Form
{
public RegisterForm()
{
InitializeComponent();
}
// button signup
private void buttonCreateAccount_Click(object sender, EventArgs e)
{
// add a new user
DB db = new DB();
MySqlCommand command = new MySqlCommand("INSERT INTO
`users`(`firstname`, `lastname`, `emailaddress`, `username`, `password`) VALUES (@fn, @ln,
@email, @usn, @pass)", db.getConnection());
command.Parameters.Add("@fn", MySqlDbType.VarChar).Value =
textBoxFirstname.Text;
command.Parameters.Add("@ln", MySqlDbType.VarChar).Value =
textBoxLastname.Text;
command.Parameters.Add("@email", MySqlDbType.VarChar).Value =
textBoxEmail.Text;
command.Parameters.Add("@usn", MySqlDbType.VarChar).Value =
textBoxUsername.Text;
command.Parameters.Add("@pass", MySqlDbType.VarChar).Value =
textBoxPassword.Text;
}
else
{
MessageBox.Show("Enter Your Informations First","Empty
Data",MessageBoxButtons.OKCancel,MessageBoxIcon.Error);
}
adapter.SelectCommand = command;
adapter.Fill(table);
}
// label go to the login form MOUSE ENTER
private void labelGoToLogin_MouseEnter(object sender, EventArgs e)
{
labelGoToLogin.ForeColor = Color.Yellow;
}
}
}
// ------ After The User Have Created His Acoount, He Need To Login To The Application, So
Let's Create The Login Form.
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_Login_And_Register
{
public partial class LoginForm : Form
{
public LoginForm()
{
InitializeComponent();
// button login
private void buttonLogin_Click(object sender, EventArgs e)
{
DB db = new DB();
adapter.SelectCommand = command;
adapter.Fill(table);