ASP.NET - change password

Asked By Rahul
10-Feb-12 03:17 AM
i have enter old password, enter new password and conform password how to easily coding to this form ? and want to save in database anybody expert give me in this style codings ?


protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

bindgrid();

}

}

 

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)

{

try

{

if (con.State == ConnectionState.Closed)

{

con.Open();

}

 

if (TextBox1.Text != "")

{

cmd = new SqlCommand("select count (id) from serve where servicename='" + TextBox1.Text + "'", con);

 

int i = (int)cmd.ExecuteScalar();

if (i == 0)

{

cmd =

new SqlCommand("insert into serve values (@servicename)", con);

cmd.Parameters.AddWithValue("servicename", TextBox1.Text);

cmd.ExecuteNonQuery();

TextBox1.Text =

"";

Response.Write("Successfull");

bindgrid();

 

//view();

}

else

{

Response.Write("Exist");

}

}

}

 

catch (Exception ex)

{

Response.Write("Error:" + ex.ToString());

}

 

finally

{

if (con.State == ConnectionState.Open)

{

con.Close();

}

}

}

 

public void bindgrid()

{

adap = new SqlDataAdapter("select * from serve", con);

ds =

new DataSet();

adap.Fill(ds);

GridView1.DataSource = ds;

GridView1.DataBind();

}

  Sreekumar P replied to Rahul
10-Feb-12 03:36 AM
Hi,

try this code to embed in ur code

SqlConnection con = new SqlConnection("Data Source=PRINEE-F495EED0;Initial Catalog=rew;Integrated Security=True");
    SqlCommand cmdchekcnmt = new SqlCommand("select count(*) from Users where username='"+Session["username"]+"' and password='"+txtOldPassword.Text+"'", con);
    con.Open();
    if (cmd.ExecuteNonQuery() > 0)
    {
 
      SqlCommand cmd;
      String str = "update Users set password=@password where username='" + Session["username"] + "' AND u_name=@u_name";
      cmd = new SqlCommand(str, con);
      cmd.Parameters.AddWithValue("@password", txt_nPW.Text);
      cmd.ExecuteNonQuery();
        
      Response.Write("Password Changed");
    }
    else
      Response.Write("Old Password don't not matches");
    }
     con.Close();
  Somesh Yadav replied to Rahul
10-Feb-12 03:45 AM
Hi try this in your code.

if (cmd.ExecuteNonQuery() > 0)
  {
 
    SqlCommand cmd;
    String str = "update Users set password=@password where username='" + Session["username"] + "' AND u_name=@u_name";
    cmd = new SqlCommand(str, con);
    cmd.Parameters.AddWithValue("@password", txt_nPW.Text);
    cmd.ExecuteNonQuery();
      
    Response.Write("Password Changed");
  }
  else
    Response.Write("Old Password don't not matches");
  }
   con.Close();
  kalpana aparnathi replied to Rahul
10-Feb-12 03:53 AM
hi,

Try this login form http://evonet.com.au/a-simple-login-form/

SqlConnection con=new SqlConnection("Your Connection String");
 
if (con.State == ConnectionState.Open)
  {
    qry = "";
    qry = "select Password,UserID from tblUsers where UserID= '" +      txtUserName.Text.Trim().Replace("'", "''") + "' and Password='" + txtPassword.Text.Trim().Replace("'", "''") + "'";
    SqlCommand cmd = new SqlCommand (qry, con);
    SqlDataReader reader = cmd.ExecuteReader();
    if (reader.Read())
    {
        //redirect to other page
    }
    else
    {
      MessageBox.Show("Please check User Name and Password");
      txtUserName.Focus();
    }
 }
  dipa ahuja replied to Rahul
10-Feb-12 04:02 AM
protected void Button1_Click(object sender, EventArgs e)
{
  //first check user is logged in or session is expired
  if (Session["user"] != null)
  {
    if (txtoldPassword.Text == txtNewPassword.Text)
    {
      Response.Write("<script>alert('your old passwod is same as new pass')</script>");
      return;
    }
    else
    {
      string user = Session["user"].ToString();
      SqlConnection conn = new SqlConnection("connectionString");
      string q = "Update users set password='" + txtNewPassword.Text
        + "' where username='" + user + "' and password='" + txtoldPassword.Text + "'";
 
      conn.Open();
      SqlCommand comm = new SqlCommand(q, conn);
      comm.ExecuteNonQuery();
      Response.Write("<script>alert('password changed')</script>");
      conn.Close();
    }
  }
  else
  {
    //if not logged in
    Response.Redirect("login.aspx");
  }
}
 
  Reena Jain replied to Rahul
10-Feb-12 04:57 AM
hi,

Here is the complete code for you to change password


if (oldpassword.Text != "" && newpassword.Text != "" && confirmpassword.Text != "")
  {
if(newpassword.Text == confirmpassword.Text ) 
{   
string connStr = ConfigurationManager.ConnectionStrings["connectionstring"].ToString();
  SqlConnection conn = new SqlConnection(connStr);
  string query = "update raqdab set Password='" + newpassword.Text + "' WHERE [Password]='" + oldpassword.Text + "'";
  conn.Open();
  SqlCommand cmd = new SqlCommand(query, conn);
  cmd.ExecuteNonQuery();
  conn.Close();
 
  oldpassword.Text = string.Empty;
  Msgg.Text = "password updated";
  }
  else
  {
  Msgg.Text = "retry";
  }
}
else
{
Msgg.Text = "new password and confirm password should be same";
}

hope this will help you
Create New Account
help
repeater's item_command getting called repeatedly upon page refresh Hi, Can some one please give me some clues about what is happening here repeater's ItemCommand (e.command = "EDIT") from where using the RegisterClientScriptBlock() I am calling another page C ameraImage.aspx as a new popup window using window.open(' cameraImage.aspx ', . . ) Here the reload()" , (5000)); in my M ainpage.aspx and after every 5 seconds it refreshes the page. But what is happening is that it is successfully refreshing but it is also going I also set the "enableviewstate = false" for my repeater control and also for the entire page I have 3 more repeater controls apart from this one but I went ahead and KC, If nothing else works, perhaps there is a caching issue? Add this under your <%@ Page . . . %> directive: <%@ OutputCache Duration = "1" VaryByParam = "*"%> Let us know what happens. Ken Hi, Actually thats how to be getting removed inspite of making enableviewstate = false for the repeater and refreshing the page. Thanks As Peter mentioned, you should post the rest of your code. That will make give people an example to work with. Ken Also wanted to mention that when the page was getting refreshed I got a message from IE saying that "to display the page IE needs to resend the information you've previously submitted" and I get this message
Error on update qry ? kindly tel me this pls ? it shows this error ? Error:System.NullReferenceException: Object reference not set to an instance of an object. at creditadd.GridView1_RowCommand Parameters.Add(param); / / to this executing correctly below this is not executing correctly it shows error ? / / cmd = new SqlCommand("update creditadd set total = @total, @total = @total + credit where cid = '" + lbid.Text set total = @total, @total = @total + credit where userid = '" + txusrid.Text + "' and username = '" + txusrname.Text + "'" , con); error it shows this line ? cmd.ExecuteNonQuery(); Response.Write( "<script> alert(Running Total Updated Successfully');< / script parameter and its value after defining sql query HEllo Can you send me your whole page code? Error:System.Data.SqlClient.SqlException: Must declare the scalar variable "@total". at System.Data.SqlClient.SqlConnection total, @total = @total + credit where userid = '" + txusrid.Text + "' and username = '" + txusrname.Text + "'" , con); cmd.ExecuteNonQuery(); / / error occurs ? cmd.Parameters.Add(param); / / cmd.Parameters.Add("@total", SqlDbType.Double, 10).Value = 0; this
2 parts to get the store name and the date. Hi Ronald, I keep gettin error message (Syntax error converting datetime from character string.) I CONVERT it to datetime but it still didnt work Maybe it because I am not reading it right from the dropdownlist. I get the error right here in SQL statement, " thedate = CONVERT(varchar(20), '" & [date] & "', 100) " . Thanks Chris [CODE] Sub date] As String = storeAndDate(1) Dim dstkiosk As DataSet dstkiosk = New DataSet Dim da As SqlDataAdapter = New SqlDataAdapter _ ("SELECT * FROM banking_pettycash WHERE checked = 0 AND cart = '" & store & "' AND thedate = CONVERT(varchar(20 ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then Call Splitstorename() End If Call Binddate() If Session("Kiosk") = "" Then Response.Redirect(". . / Login Sub Private Sub ImageButton1_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Response.Redirect(". . / AdminSite / AdminPanel.aspx") End Sub Sub Binddate() If DropDownList1.SelectedIndex = 0 Then DataGrid1 date] As String = storeAndDate(1) Dim dstkiosk As DataSet dstkiosk = New DataSet Dim da As SqlDataAdapter = New SqlDataAdapter _ ("SELECT * FROM banking_pettycash WHERE checked = 0 AND cart = '" & store & "' AND [date] = CAST
view i create 3 gridview in one page . . .after hosting no any one gridview display . . .why? is possible for 3 gridview in one page. . . . . in local host succesfull run. . .this problem occure in server Hi, Just check connection string bind with gridview. Please check and let us know Hi sri, Gridview not visible in Page Any kind of data u can bind with the grid view.you should assign the in the browser only if we bound any data. More than 1 Gridview in a page More than 1 gridview is not possibel There's certainly no technical reason why you can't have more than one GridView and / or FormView on the same page. . . Whether that's "good practice" or not is impossible to say without knowing how the page actually works / looks Put the gridview inside the ispostback condition protected void Page_Load( object sender its also display but group_master form have 3 gridview which form no visible gridview. . .this error occure in server side only <% @ Page Language = "C#" MasterPageFile = "~ / Admin / MasterPage.master" AutoEventWireup = "true" CodeFile = "Group_Master.aspx.cs" Inherits = "Admin_Group_Master" Title
is updtate running total how to do this in this codings ? this is my whole page code: using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq using System.Xml.Linq; using System.Data.SqlClient; public partial class creditdeduct : System.Web.UI. Page { SqlConnection con = new SqlConnection ( ConfigurationManager .ConnectionStrings[ "tour" ].ConnectionString); SqlCommand cmd; SqlDataAdapter adap; DataSet ds; SqlDataReader dr; double total; / / float f; protected void Page_Load( object sender, EventArgs e) { if (!IsPostBack) { bindgrid dropbind(); } } protected void ImageButton1_Click( object sender, ImageClickEventArgs e) { try { if (con.State = = ConnectionState .Closed) { con.Open(); } cmd = new SqlCommand ( "select Count(*) from script> " ); bindgrid(); } else { Response.Write( "<script> alert('Not Registered');< / script> " ); } } } catch ( Exception ex) { Response.Write( "Error:" + ex.ToString()); } finally { if (con.State = = ConnectionState .Open) { con.Close(); } } } public void bindgrid() { adap = new SqlDataAdapter ( "select creditdeduct.cid, convert(char(12), creditdeduct.fromdate, 103)as fromdate, creditdeduct.userid, creditdeduct.username serve.servicename from creditdeduct inner join serve on serve.id = creditdeduct.services" , con); / / adap = new SqlDataAdapter("select creditadd.cid, creditadd.userid, creditadd.username, creditadd.credit, creditadd.total, serve.servicename from creditadd