Click here to Skip to main content

Member 9756819 asked:

Open original thread
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class Change_Password : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
 

    public string UsrID
    { get; set; }
 

 
    private void ShowResult(string _msg)
    {
        divmsg2.Visible = true;
        ltrmsg2.Text = _msg;
    }
 

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
 

            if (String.IsNullOrEmpty(TxtOldPass.Text) || String.IsNullOrEmpty(TxtNewPass.Text) || String.IsNullOrEmpty(TxtConfPass.Text))
            {
                ShowResult("Please fill in the fields");
            }
 
            else
            {
 
                if (Context.User.Identity.IsAuthenticated)
                {
 
                    usermasterDataContext context = new usermasterDataContext();
                    var data = context.passwords.Single(m => m.UsrPassword == TxtOldPass.Text);
                    var UID = context.passwords.Where(i => i.UsrPassword==TxtOldPass.Text).Select(i => i.ID).ToList();
                   
                    foreach (int i in UID)
                    {
                        UsrID = i.ToString();
                    }
                    string oldpass = data.UsrPassword.ToString();
                    string newpass = TxtNewPass.Text;
                    string confpass = TxtConfPass.Text;
 
                    if (oldpass == TxtOldPass.Text)
                    {
                        var data2 = (from p in context.passwords
                                     where p.ID == Convert.ToInt64(UsrID)
                                     select p).Single();
 
                        data2.UsrPassword = newpass.ToString();
                        context.SubmitChanges();
                     
                        ShowResult("Password Changed Successfully");
                        //Panel1.Visible = false;
                       
                    }
                    else
                    {
                        ShowResult("Old password does not match");
                        return;
                    }
                    if (TxtConfPass.Text != TxtNewPass.Text)
                    {
                        ShowResult("New Password and Confirm Password do not match");
                        return;
                    }
                }
 
            }
        }
 
        catch
        {
            ShowResult("Some error occured. Please try again later!");
        }
 
        finally
        {
            TxtOldPass.Text = "";
            TxtNewPass.Text = "";
            TxtConfPass.Text = "";
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Panel1.Visible = false;
        LinkButton lb = (LinkButton)this.Parent.FindControl("lnkChangepwd");
        lb.Visible = true;
    }
}
Tags: ASP:NET

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid