I have created similar form during my training period, it may help you.
Before going to coding part you need to create table which include all above item. I have developed the logic with the help of store procedure. I have created store procedure
IF NOT EXISTS (SELECT UserId FROM User_information
where
UserId = @UserId) BEGIN
PRINT 'No Such
UserId Exist' END ELSE begin declare @checkpass varchar(30); set @checkpass= (SELECT User_Password
FROM User_information where UserId =
@UserId) if (@Checkpass<> @Old_Password) begin print 'old password is wrong' end ELSE IF (@New_Password <> @confirm_new_password) BEGIN PRINT 'Password doesn''t
match' END ELSE BEGIN UPDATE
User_information SET User_Password=
@confirm_new_password , Password_Hint= @Password_Hint WHERE UserId =
@UserId END END END
Here is the complete code for the reset form:
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 System.Data.SqlClient; namespace FormsApplication1 { publicpartialclassForm3 : Form { public Form3() { InitializeComponent(); } privatevoid button1_Click(object sender, EventArgs e) { SqlConnection con = newSqlConnection(); con.ConnectionString = (@"Data Source=msclient-012\sqlexpress;Initial Catalog=testing_st;User ID=sa;Password=mindstick"); con.Open(); SqlCommand cmdreset = newSqlCommand("User_Info", con); cmdreset.Connection = con; cmdreset.CommandType = CommandType.StoredProcedure; cmdreset.Parameters.AddWithValue("@Old_Password", textBox1.Text); cmdreset.Parameters.AddWithValue("@UserId", textBox5.Text); cmdreset.Parameters.AddWithValue("@New_Password", textBox2.Text); cmdreset.Parameters.AddWithValue("@confirm_new_password", textBox3.Text); cmdreset.Parameters.AddWithValue("@Password_Hint", textBox4.Text); if (textBox5.Text.Trim() == string.Empty) { MessageBox.Show("Userid required","Warning Message"); } else { if(textBox1.Text.Trim() == string.Empty) { MessageBox.Show("Old Password Required!!","Warning Message"); } else { if(textBox2.Text.Trim() == string.Empty) { MessageBox.Show("New password required","Warning Message"); } else { if (textBox3.Text.Trim() == string.Empty) { MessageBox.Show("Confirm Password Required","Warning Message"); } else {
cmdreset.ExecuteNonQuery(); SqlCommand cmd = newSqlCommand("Select UserId from User_information where UserId=@UserId and User_Password=@User_Password", con); // SqlCommand cmd = new
SqlCommand("Login_Check_Sp", con); // cmd.CommandType =
CommandType.StoredProcedure; DataTable dt = newDataTable(); cmd.Parameters.AddWithValue("@UserId", textBox5.Text);
cmd.Parameters.AddWithValue("@User_Password", textBox2.Text); SqlDataReader read = cmd.ExecuteReader(); read.Read(); if (read.HasRows) { MessageBox.Show("Successfully changed the Password ","Contrats Message"); read.Close(); this.Close(); } else { read.Close(); SqlCommand cmd1 = newSqlCommand("Select UserId from User_information where UserId=@UserId and User_Password=@User_Password", con); // SqlCommand cmd = new
SqlCommand("Login_Check_Sp", con); // cmd.CommandType =
CommandType.StoredProcedure; DataTable dt1 = newDataTable();
cmd1.Parameters.AddWithValue("@UserId", textBox5.Text); cmd1.Parameters.AddWithValue("@User_Password", textBox1.Text); SqlDataReader read1 =
cmd1.ExecuteReader(); read1.Read(); if (read1.HasRows) { //here you may
redirect to another page like Response.Redirect("Page2.aspx"); MessageBox.Show("Password mismatich ","Warning Message"); read1.Close(); } else { MessageBox.Show("Old Password is wrong","Warning Message"); } } con.Close(); } } } } } privatevoid button2_Click (object sender, EventArgs e) { this.Close(); } privatevoid textBox1_TextChanged(object sender, EventArgs e) { textBox1.PasswordChar = '*'; textBox1.MaxLength = 8; } privatevoid textBox2_TextChanged(object sender, EventArgs e) { textBox2.PasswordChar = '*'; textBox2.MaxLength = 8; } privatevoid textBox3_TextChanged(object sender, EventArgs e) { textBox3.PasswordChar = '*'; textBox3.MaxLength = 8; } } }
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
I have created store procedure
Here is the complete code for the reset form: