hi..
I have three fields
1. current password
2. new password
3. confirm password
after login the form using user id.(user id is primary key for change password form database table)
using user id i want to check the current password for user and then update the new password to database table.
help me
Advanx thx..!
Sudharsan S
Loading
Satyapriya NayakPosted Jun 12, 2012, 3:09 PM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Password_Change_in_asp.net._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Password_Change_in_asp.net
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str = null;
SqlCommand com;
protected void btn_login_Click(object sender, EventArgs e)
{
object obj = null;
SqlConnection con = new SqlConnection(strConnString);
con.Open();
Session["UserName"] = TextBox_user_name.Text;
str = "select count(*) from login where UserName=@UserName and Password =@Password";
com = new SqlCommand(str, con);
com.CommandType = CommandType.Text;
com.Parameters.AddWithValue("@UserName", Session["UserName"]);
com.Parameters.AddWithValue("@Password", TextBox_password.Text);
obj = com.ExecuteScalar();
if ((int)(obj) != 0)
{
Response.Redirect("Welcome.aspx");
}
else
{
lb1.Text = "invalid user name and password";
}
con.Close();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Welcome.aspx.cs" Inherits="Password_Change_in_asp.net.Welcome" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace Password_Change_in_asp.net
{
public partial class Welcome : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lb1.Text = "WELLCOME :: " + Session["UserName"];
}
protected void lnk_changepassword_Click(object sender, EventArgs e)
{
Response.Redirect("Changepassword.aspx");
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Changepassword.aspx.cs" Inherits="Password_Change_in_asp.net.Changepassword" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Password_Change_in_asp.net
{
public partial class Changepassword : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str = null;
SqlCommand com;
byte up;
protected void btn_update_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from login ";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
if (txt_cpassword.Text == reader["Password"].ToString())
{
up = 1;
}
}
reader.Close();
con.Close();
if (up == 1)
{
con.Open();
str = "update login set Password=@Password where UserName='" + Session["UserName"].ToString()+ "'";
com = new SqlCommand(str, con);
com.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 50));
com.Parameters["@Password"].Value = txt_npassword.Text;
com.ExecuteNonQuery();
con.Close();
Response.Write("Password changed");
}
else
{
Response.Write("Please enter correct Oldpassword");
}
}
}
}
Thanks
If this post helps you mark it as answer
sudharsan sPosted Jun 14, 2012, 2:58 AM
Posted Jun 12, 2012, 8:57 AM
Old password should not be empty
New password and confirm password should be same
New password should not be same as old password.
New password or confirm password should be empty.
Once the above validations are done, send the old password, new password and user id field values to stored procedure.
Step 1 : Validate whether, the user entered valid old password or not for that UserId
Step 2: Update Password column value with the new password.
Redirect the user to login page, in order to use new password or update your session / static information values.
Hope this helps you.