protected void PasswordSaveButton_Click(object sender, EventArgs e) { long userid = Convert.ToInt64(Session["UserID"]); string oldpassword = OldPasswordTextBox.Text; string newpassword = NewPasswordTextBox.Text; string confirmpassword = Server.HtmlEncode(ConfirmPasswordTextBox.Text); string hash = null; string salt = null; string goodHash = null; bool chk = false; UserBL userBL = new UserBL(); var user = userBL.GetUsersByID(userid); if(user.Count()>0) { hash = user.ElementAt(0).Password; salt = user.ElementAt(0).PasswordSalt; goodHash = "1000:" + salt + ":" + hash; chk = Authentication.ValidatePassword(oldpassword,goodHash); } if (chk == true) { if(newpassword.Length >=6) { if(newpassword == confirmpassword) { // save password ErrorLabel.Text = "Success and Saved!"; userBL.SetPassword(newpassword); TextBox pe = (TextBox)UsersDetailsView.FindControl("PasswordTextBox"); pe.Text = newpassword; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "CloseModal('BodyContent_ModalPanel1');", true); } else { // new and confirm did not match ErrorLabel.Text = "Confirm Password did not match! Please try again"; } } else { // more than 6 char ErrorLabel.Text = "Password length should be more than 5 characters"; } } else { // password not match; ErrorLabel.Text = "Wrong Password! Please try again."; } }