In This tutorial you will Learn about how to Create Login in C# , How to Update your Password in C# Desktop application , How to Change Password in C# Desktop application step by Step . we are sharing Source code with you Guys as well
Create Login
- Open Your Visual Studio with new App
- Select C# Windows application
- Write Name of application
- Add application form
- Draw two text Boxes
- one button for Login
- Create Database in MSSQL
- make connection with Database using App.Config Like This
<connectionStrings> <add name=”abc” connectionString=”Data Source=DESKTOP-3V7KQ4B\SQLEXPRESS;Initial Catalog=shop; Integrated Security=True” providerName=”System.Data.SqlClient”/> </connectionStrings> |
Detail of connection string
Add Name is used to save connection in string
Data Source is used to save your SQL server information
Intial catalog is used to save your Database name
- Now write Login Code
- write this code Behind the Button
if(textBox1.Text ==”” ||textBox2.Text ==””) { MessageBox.Show(“Please provide UserName and Password”); return; } try { //Create SqlConnection string cs = ConfigurationManager.ConnectionStrings[“abc”].ConnectionString; SqlConnection con = new SqlConnection(cs); SqlCommand cmd = new SqlCommand(“Select * from login where username=@username and Password=@password”,con); cmd.Parameters.AddWithValue(“@username”, textBox1.Text); cmd.Parameters.AddWithValue(“@password”, textBox2.Text); con.Open(); SqlDataAdapter adapt = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adapt.Fill(ds); con.Close(); int count = ds.Tables[0].Rows.Count; //If count is equal to 1, than show frmMain form if (count == 1) { this.Hide(); shop_Detail f1 = new shop_Detail(); f1.Show(); } else { MessageBox.Show(“Login Failed!”); } } catch(Exception ex) { MessageBox.Show(ex.Message); } } |
Now Update password
- Update Password Form will be like this
- Draw three text boxes one for Old Password , New Password , confirm password and one Update button
- database will be like this
- Now write code Behind the Update button
{ string cs = ConfigurationManager.ConnectionStrings[“abc”].ConnectionString; cmd.ExecuteNonQuery(); } |
You can download Complete Source code .sln file
Leave a Comment