In this article, I'm gonna share about how to make login and register form with MS SQL database;
1. Flow Chart Logic
2. Normal Features
Login Form Design
Sign in Form Design
Password Retrieve Form
4. Database Design and SQL queries and Stored Procedure
Create new Database as "schooldata"
create table registerdata
(
ID int identity,
Username nvarchar(100),
Password nvarchar(100),
Fullname nvarchar(100),
MobileNO nvarchar(100),
EmailID nvarchar(100)
)
select * from registerdata
create procedure regis
(
@Username as nvarchar(100),
@Password as nvarchar(100),
@Fullname as nvarchar(100),
@MobileNO as nvarchar(100),
@EmailID as nvarchar(100)
)
as begin
insert into registerdata (Username, Password, Fullname, MobileNO,EmailID)
values (@Username, @Password, @Fullname, @MobileNO, @EmailID)
end
5. App.config Settings
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="ConnData"
connectionString="Data Source=localhost\sqlexpress;Initial Catalog=Schooldata;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
6. SignIn Form Coding
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.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Net;
using System.Collections.Specialized;
namespace SchoolData
{
public partial class LoginForm : Form
{
public LoginForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SigninForm sf = new SigninForm();
sf.Show();
this.Hide();
}
private void button2_Click(object sender, EventArgs e)
{
if ((textBox1.Text != "") && (textBox2.Text != ""))
{
string constring = ConfigurationManager.ConnectionStrings["ConnData"].ConnectionString;
SqlConnection con = new SqlConnection(constring);
string q = "select * from registerdata where Username = @Username and Password = @Password ";
SqlCommand cmd = new SqlCommand(q, con);
cmd.Parameters.AddWithValue("@Username", this.textBox1.Text);
cmd.Parameters.AddWithValue("@Password", this.textBox2.Text);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (dr.HasRows == true)
{
MessageBox.Show("Login Successfully Done");
}
}
if (dr.HasRows == false)
{ MessageBox.Show("Access Denied, password username mismatched"); }
}
else { MessageBox.Show("Enter username and password"); }
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
RetrievePwdForm rf = new RetrievePwdForm();
rf.Show();
this.Hide();
}
}
}
7. Register Form
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.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Net;
using System.Collections.Specialized;
namespace SchoolData
{
public partial class SigninForm : Form
{
public SigninForm()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
//checking whether username already exist
public void UserNameCheck()
{
string constring = ConfigurationManager.ConnectionStrings["ConnData"].ConnectionString;
SqlConnection con = new SqlConnection(constring);
SqlCommand cmd = new SqlCommand("Select * from registerdata where Username= @Username", con);
cmd.Parameters.AddWithValue("@Username", this.textBox1.Text);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (dr.HasRows == true)
{
MessageBox.Show("Username = "+ dr[1].ToString() +" Already exist");
break;
}
}
//return textBox1.Text ;
}
// clear all values in textbox
public void clearall()
{
textBox1.Text = " ";
textBox2.Text = " ";
textBox3.Text = " ";
textBox4.Text = " ";
textBox5.Text = " ";
}
//checking whether mobile number already exist
public void MobileNOCheck()
{
string constring = ConfigurationManager.ConnectionStrings["ConnData"].ConnectionString;
SqlConnection con = new SqlConnection(constring);
SqlCommand cmd = new SqlCommand("Select * from registerdata where MobileNO= @MobileNO", con);
cmd.Parameters.AddWithValue("@MobileNO", this.textBox4.Text);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (dr.HasRows == true)
{
MessageBox.Show("MobileNO = " + dr[4].ToString() + "is Already exist");
break;
}
}
//return textBox4.Text;
}
public void datastore()
{
string Fname, Sname, Fullname, MobileNO, EmailID;
Fname = textBox1.Text;
Sname = textBox2.Text;
Fullname = textBox3.Text;
MobileNO = textBox4.Text;
EmailID = textBox5.Text;
try
{
string constring = ConfigurationManager.ConnectionStrings["ConnData"].ConnectionString;
/* Declaring Connection Variable */
SqlConnection con = new SqlConnection(constring);
/* Checking Connection is Opend or not If its not open the Opens */
if (con.State != ConnectionState.Open)
con.Open();
/* Calling Stored Procedure as SqlCommand */
SqlCommand cmd = new SqlCommand("regis", con);
cmd.CommandType = CommandType.StoredProcedure;
/* Passing Input Parameters with Command */
cmd.Parameters.AddWithValue("@Username", Fname);
cmd.Parameters["@Username"].Direction = ParameterDirection.Input;
cmd.Parameters.AddWithValue("@Password", Sname);
cmd.Parameters["@Password"].Direction = ParameterDirection.Input;
cmd.Parameters.AddWithValue("@Fullname", Fullname);
cmd.Parameters["@Fullname"].Direction = ParameterDirection.Input;
cmd.Parameters.AddWithValue("@MobileNO", MobileNO);
cmd.Parameters["@MobileNO"].Direction = ParameterDirection.Input;
cmd.Parameters.AddWithValue("@EmailID", EmailID);
cmd.Parameters["@EmailID"].Direction = ParameterDirection.Input;
/* Executing Stored Procedure */
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Data Inserted Succesfully");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void registerdata()
{ datastore();
this.Hide();
LoginForm lf = new LoginForm();
lf.Show();
}
private void button1_Click(object sender, EventArgs e)
{
registerdata();
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
//UserNameCheck();
//clearall();
}
private void textBox4_KeyDown(object sender, KeyEventArgs e)
{
//MobileNOCheck();
//clearall();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
//UserNameCheck();
//clearall();
}
private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
{
//MobileNOCheck();
//clearall();
}
private void textBox4_KeyUp(object sender, KeyEventArgs e)
{
//MobileNOCheck();
//clearall();
}
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
//UserNameCheck();
//clearall();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
UserNameCheck();
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
// MobileNOCheck();
}
private void textBox4_TextChanged_1(object sender, EventArgs e)
{
MobileNOCheck();
}
}
}
8. Retrieve Password Form
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.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Net;
using System.Collections.Specialized;
namespace SchoolData
{
public partial class RetrievePwdForm : Form
{
public RetrievePwdForm()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
this.Hide();
LoginForm lf = new LoginForm();
lf.Show();
}
private void button1_Click(object sender, EventArgs e)
{
string constring = ConfigurationManager.ConnectionStrings["ConnData"].ConnectionString;
SqlConnection con = new SqlConnection(constring);
SqlCommand cmd = new SqlCommand("Select * from registerdata where MobileNO= @MobileNO", con);
cmd.Parameters.AddWithValue("@MobileNO", this.textBox1.Text);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (dr.HasRows == true)
{
string str = "Your Password = ";
label2.Text=str + dr[2].ToString();
}
}
}
}
}
Output
a) Register New User and store into database
b) Check Username already Exist
C) Check Mobile Number Already Exist
D) Forget Password
Finally Login Successfully done
ConnectionStrings not work! why?
ReplyDeletelorphethna@gmail.com
ReplyDeleteshows error in the name 'ConfigurationManager' does not exist in the current context
ReplyDeleteThank you very much! (^_^)
ReplyDeleteIt's so useful for me to learn. Thanks :)
If I continue to click Register Button in SinginForm even though it announces error:"Both Username and MobileNO are already exist!",
ReplyDeleteit's still save datas into database and it is "Polymeric Datas about Username and MobileNO". Do you have solutions to resolve it? Please, help me!
Thank you very much! (^_^)
ReplyDeleteIt's so useful for me to learn. Thanks :)
your welcome
Deletethank you very much
Deleteis this necessary to add configuration in app config?
ReplyDeletecan you please upload complete project ???
ReplyDeleteHow to make the values @Username , @Password ?
ReplyDeletewhen I register then showing
ReplyDeleteconfiguration system failed to initialize
Great info provided, thanks for the help. cpDESK is Online Web Development Tool Company located in Canada.For more details please visit our site - Web Application Development Tool Company | cpDESK
ReplyDeletehey Sir, Would u like to send me the full source code with database on manwendrapratapsingh@gmail.com
ReplyDeleteYour good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
ReplyDeleteDevops Training courses
python Training in chennai
Devops Training in Bangalore
ReplyDeleteReally nice topics you had discussed above. I am much impressed. Thank you for providing this nice information here.
Hire Windows Application Developer
HOW CAN I DOWNLOAD THAT PROJECT? MAY YOU ASSIST
ReplyDeletenice blog
ReplyDeletedevops training in bangalore
hadoop training in bangalore
iot training in bangalore
machine learning training in bangalore
uipath training in bangalore
VISIT HERE ==> BIG DATA AND HADOOP TRAINING IN BANGALORE
ReplyDeleteif you want to pop up your website then you need mail office 365 sign in
ReplyDeleteI have truthfully never come across such overwhelmingly good piece of content. I agree with your valid points and your ideas. This piece of information is really great.
ReplyDeleteThank you so much.
SAP training in Kolkata
SAP course in kolkata
Thanks for your interesting ideas.the information's in this blog is very much useful for me to improve my knowledge.salesforce training in chennai
ReplyDeletesoftware testing training in chennai
robotic process automation rpa training in chennai
blockchain training in chennai
devops training in chennai
It is extremely nice to see the greatest details presented in an easy and understanding manner. ExcelR Data Analyst Course
ReplyDeleteThanks for the Valuable information.Really useful information. Thank you so much for sharing. It will help everyone.
ReplyDeleteTableau Training in Delhi.
FOR MORE INFO:
Thanks for sharing this article with us keep sharing and writing.
ReplyDeleteData Science Training in Pune
Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site. And Stock market is a place where many new stock market traders join the share trading league daily and trade daily in Share Tips, Intraday traders, Stock Market investors and market beginners should understand the meaning of the stock market for beginners cutting the learning curve.
ReplyDeleteWell-written and informative blog. Keep sharing more.
ReplyDeleteAI Course with Placements in Hyderabad
Extraordinary Blog. Provides necessary information.
ReplyDeletebest digital marketing course in chennai
best digital marketing training in chennai
Really an awesome blog, Informative content. Keep sharing more stuff like this. Thank you.
ReplyDeleteOnline Data Science Training in Hyderabad
Online Data Science Course in Hyderabad
This post is so interactive and informative.keep update more information...
ReplyDeleteDevOps course in Tambaram
DevOps Training in Chennai
Nice Article. Thanks you for sharing this.
ReplyDeleteAntimony Lead Alloys
Interesting and Amazing blog, Thanks for this useful knowledge-sharing blog.
ReplyDeleteHenna Powder Hair Colors
Thank you for sharing such a nice blog. I really enjoy while reading it to know deeply
ReplyDeleteYou can put your thought here at articlesvibe.site
Mindblowing blog very useful thanks
ReplyDeleteDevOps Training in Velachery
DevOps Training in Chennai
Hello, thank you for the information. I have been able to obtain new information here. However, I use this page to specialize in some technical problems. I have reloaded the page many times, so I was able to load it correctly. I wonder if your web host was OK.정읍출장샵
ReplyDelete남원출장샵
군산출장샵
전주출장샵
김제출장샵
김해출장샵
밀양출장샵
ReplyDeletevery nice website with good content.will sure visit again. Thanks
https://rankingtop.in/
https://techhitech.in/
https://matrixmanpowersolutions.xyz/
https://advertise.techhitech.in/
https://speedzpackersmovers.in/
https://topranker.xyz/
https://rapidshift.co.in/
https://rapidshiftpackers.com/
nicely explained article. thanks for sharing
ReplyDeletehttps://vmsdcc.co.in/