Create Login form by using select query

create login screen in c# using select query
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lab_14_create_register_database_login
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void label4_Click(object sender, EventArgs e)
{
this.Hide();
Form2 fm2 = new Form2();
fm2.Show();

}

private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("Please Enter Email");
return;
}
if (textBox2.Text == "")
{
MessageBox.Show("Please Enter Password");
return;
}
bool iseq = false;
SqlConnection conn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=RegisterDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
SqlCommand cmd = new SqlCommand(@"SELECT Email,Password FROM regtable", conn);
cmd.Parameters.AddWithValue("@email", textBox1.Text);
cmd.Parameters.AddWithValue("@password", textBox2.Text);
conn.Open();
SqlDataReader read = cmd.ExecuteReader();
while (read.Read())
{

//label3.Text = "Name is " + read["Email"].ToString();
string em = read["Email"].ToString();
string pswn = read["Password"].ToString();
if (textBox1.Text.Equals(em) && textBox2.Text.Equals(pswn))
{
iseq = true;

}

}
conn.Close();
if (iseq == true)
{
MessageBox.Show("Successfull Login");
this.Hide();
Form4 fm4 = new Form4();
fm4.Show();
}
else if(iseq == false)
{
MessageBox.Show("Invalid Login Details");

}



}

private void label6_Click(object sender, EventArgs e)
{

this.Hide();
Form3 fm3 = new Form3();
fm3.Show();
}
}
}

Create Registration form by using Insert query

create Registration form by using Insert query
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lab_14_create_register_database_login
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void label7_Click(object sender, EventArgs e)
{
this.Hide();
Form1 fm1 = new Form1();
fm1.Show();
}

private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("Please Enter First Name");
return;
}
if (textBox2.Text == "")
{
MessageBox.Show("Please Enter Last Name");
return;
}
if (textBox3.Text == "")
{
MessageBox.Show("Please Enter City");
return;
}
if (textBox4.Text == "")
{
MessageBox.Show("Please Enter Email");
return;
}
if (textBox5.Text == "")
{
MessageBox.Show("Please Enter Password");
return;
}
SqlConnection conn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=RegisterDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
SqlCommand cmd = new SqlCommand(@"INSERT INTO regtable (FirstName,LastName,City,Email,Password) VALUES (@firstname,@lastname,@city,@email,@password)", conn);
cmd.Parameters.Add("@firstname", textBox1.Text);
cmd.Parameters.Add("@lastname", textBox2.Text);
cmd.Parameters.Add("@city", textBox3.Text);
cmd.Parameters.Add("@email", textBox4.Text);
cmd.Parameters.Add("@password", textBox5.Text);
conn.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{

MessageBox.Show("Successfull Registered");
}
conn.Close();

}
}
}

Create forgot Password form by using update query

create forgot Password form by using update query in c sharp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lab_14_create_register_database_login
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
if (textBox3.Text == "")
{
MessageBox.Show("Please Enter Email");
return;
}
if (textBox4.Text == "")
{
MessageBox.Show("Please Enter City");
return;
}
if (textBox1.Text == "")
{
MessageBox.Show("Please Enter New Password");
return;
}
if (textBox2.Text == "")
{
MessageBox.Show("Please Enter Confirm Password");
return;
}
string email, city, password;
email = textBox3.Text;
city = textBox4.Text;
password = textBox2.Text;
if(textBox1.Text == password)
{
SqlConnection conn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=RegisterDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
string q = "update [regtable] set [Password]='" + password + "' where Email='" + email + "' and City='" + city + "'";
SqlCommand cmd = new SqlCommand(q, conn);
conn.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
MessageBox.Show("Password Successfully Changed");
}
else
{
MessageBox.Show("Sorry Your Details are Wrong");
}
conn.Close();
}
else
{
MessageBox.Show("Sorry your New Password and Confirm password is not Match");
}


}

private void button2_Click(object sender, EventArgs e)
{
this.Hide();
Form1 fm1 = new Form1();
fm1.Show();

}
}
}

Create Administrator form that can delete any record by using delete query

Create Administrator form that can delete any record by using delete query in c#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lab_14_create_register_database_login
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)
{
this.Hide();
Form1 fm1 = new Form1();
fm1.Show();
}

private void button1_Click(object sender, EventArgs e)
{
string email;
email = textBox1.Text;
SqlConnection conn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=RegisterDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
string q = "delete from regtable where Email='" + email + "'";
SqlCommand cmd = new SqlCommand(q, conn);
conn.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
MessageBox.Show($"{email} Record Seccessfully Deleted");
}
else
{
MessageBox.Show("Sorry Email Address is Wrong");
}
conn.Close();
}
}
}

Create Select Method Form

select method to forgot password in c#
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 Lab_14_create_register_database_login
{
public partial class forgotmethod : Form
{
public forgotmethod()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
this.Hide();
Form3 fm3 = new Form3();
fm3.Show();
}

private void button2_Click(object sender, EventArgs e)
{
sendcode sc = new sendcode();
this.Hide();
sc.Show();
}

private void button3_Click(object sender, EventArgs e)
{
this.Hide();
Form1 fm1 = new Form1();
fm1.Show();
}
}
}

Create Form to generate code on gmail and verify code

send and receive code on gmail and verify code in c# using database
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lab_14_create_register_database_login
{
public partial class sendcode : Form
{
string randomcode;
public static string to;
public sendcode()
{
InitializeComponent();
}

private void label4_Click(object sender, EventArgs e)
{
this.Hide();
forgotmethod fm = new forgotmethod();
fm.Show();
}

private void button1_Click(object sender, EventArgs e)
{
string from, pass, messagebody;
Random rand = new Random();
randomcode = (rand.Next(999999)).ToString();
MailMessage message = new MailMessage();
to = (textBox1.Text).ToString();
from = "csdeptest@gmail.com";
pass = "1234cs1234";
messagebody = $"Your Reset Code is {randomcode}";
message.To.Add(to);
message.From = new MailAddress(from);
message.Body = messagebody;
message.Subject = "Password Reset Code";
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.EnableSsl = true;
smtp.Port = 587;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(from,pass);
try
{
smtp.Send(message);
MessageBox.Show("Code Send Succesfully");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void button2_Click(object sender, EventArgs e)
{
if(randomcode == (textBox2.Text).ToString())
{
to = textBox1.Text;
resetpassword rp = new resetpassword();
this.Hide();
rp.Show();
}
else
{
MessageBox.Show("Worng Code");
}
}
}
}

Create New Password and Confirm Password Form

Create new password and confirm password form in c#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lab_14_create_register_database_login
{
public partial class resetpassword : Form
{
string username = sendcode.to;
public resetpassword()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)
{
this.Hide();
Form1 fm1 = new Form1();
fm1.Show();
}

private void button1_Click(object sender, EventArgs e)
{

string password = textBox2.Text;
if(textBox1.Text == textBox2.Text)
{
SqlConnection conn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=RegisterDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
string q = "update [regtable] set [Password]='" + password + "' where Email='" + username + "'";
SqlCommand cmd = new SqlCommand(q, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();

MessageBox.Show("Password Successfully Changed");

}
else
{
MessageBox.Show("Sorry your New Password and Confirm password is not Match");
}
}
}
}

Contact us - WSP Tech - World Solution Point Technologies

Contact Details for C# Projects

If you want any Project then contact our Customer support

Email: support@wsptech.pk

Mobile no: +92 304 5180559

You can contact any time on Mobile Number.