Click here to Skip to main content
16,011,988 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i used this code for change my current password and i whant to change my current user name and password.thanks

Change password code(DATA LAYER)
C#
public int DLChangePassword(string UserName, string Oldpwd)
{
    con.Open();
    SqlCommand cmd;

    String sql = "SELECT * FROM tbluser WHERE UserName=@UserName AND Password = @Password";
    cmd = new SqlCommand(sql, con);
    cmd.Parameters.AddWithValue("@UserName", UserName);
    cmd.Parameters.AddWithValue("@Password", Oldpwd);
    SqlDataReader reader = cmd.ExecuteReader();
    if (reader != null && reader.HasRows)
    {
        con.Close();
        return 1;
    }
    else
    {
        con.Close();
        return 0;

    }
}
public string Update(string UserName, string Newpwd)
{
    con.Open();
    string str = "Update tbluser set Password=@Password where AdminName=@AdminName";
    SqlCommand cmd = new SqlCommand(str, con);
    cmd.Parameters.AddWithValue("@AdminName", UserName);
    cmd.Parameters.AddWithValue("@Password", Newpwd);
    cmd.ExecuteNonQuery();
    con.Close();
    return "success full change";
}

Change password(BL code)
C#
public int BLChangePassword(string UserName, string Oldpwd)
{

    return obj.DLChangePassword(UserName, Oldpwd);

}
public string BLupdate(string UserName, string Newpwd)
{

    return obj.Update(UserName, Newpwd);
}

Change password(LOGIN.ASPX.CS)
C#
protected void btnChangePwd_Click(object sender, EventArgs e)
{
    clsBLayer obj = new clsBLayer();
    if (txtCurentPwd.Text != txtCurentPwd.Text)
    {
        lblMsg.Text = "Retype Password Miss-match Try Agan";
        txtCurentPwd.Text = txtNewPwd.Text= "";

    }
    else
    {
        int a = (int)obj.BLChangePassword(txtCurentUserName.Text, txtNewPwd.Text);
        if (a != 0)
        {
            lblMsg.Text = obj.BLupdate(txtCurentUserName.Text, txtNewPwd.Text);
            txtCurentPwd.Text = txtReptPwd.Text = txtNewPwd.Text = "";
        }
        else
        {
            lblMsg.Text = "User And Password not Exist";
        }
    }
}

Thanks to all of you.
Posted
Updated 8-Aug-13 23:59pm
v2
Comments
[no name] 9-Aug-13 5:45am    
And your question/problem is what?
venkateshCST 9-Aug-13 5:46am    
Do you want to change user name as well password at same time? If u want to do like that then you need to change ur query string str = "Update tbluser set Password=@Password,AdminName=@AdminName where AdminID=@AdminID";Here AdminID is a primary key you need to update by PK ...
[no name] 9-Aug-13 6:01am    
It seems you are wondering with your question and hv not mentioned yet here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900