locked
How do i implement change password in asp.net using Entity Framework RRS feed

  • Question

  • User186310208 posted

    Can someone help me...how do i implement change password firstly it checks old password matches and then update new password in database in asp.net Using entity Framework..

    below is my design code..

    <div class="col-md-12 col-sm-12 col-xs-12 user-login-box">
    <table class="style1">
    <tr>
    <td>Current Password:</td>
    <td>
    <asp:TextBox ID="TxtCrntPswd" runat="server"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td>New Password:</td>
    <td>
    <asp:TextBox ID="TxtNwPswd" runat="server"></asp:TextBox>
    </td>
    </tr>

    <tr>
    <td>Confirm New Password:</td>
    <td>
    <asp:TextBox ID="TxtCnPswd" runat="server"></asp:TextBox>
    </td>
    </tr>


    </table>
    </div>
    <asp:Button ID="BtnPswd" runat="server" Text="Save" OnClick="BtnPswd_Click" />
    <asp:Label ID="lbl_msg" Font-Bold="True" BackColor="#FFFF66" ForeColor="#FF3300" runat="server" Text=""></asp:Label><br /><br />
    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Profile.aspx">Login</asp:HyperLink>

    </div>

    </div>

    </div>

    Wednesday, July 29, 2020 11:05 AM

Answers

  • User186310208 posted

    This is working....

    protected void BtnPswd_Click(object sender, EventArgs e)
    {
    using (var context = new WallpaperEntities4())
    {
    var currPass = TxtCrntPswd.Text;
    var newPass = TxtNwPswd.Text;
    var rePass = TxtCnPswd.Text;
    string UserName = Convert.ToString(Session["UserName"]);

    User userEntity = (from x in context.Users
    where x.UserName == UserName
    && x.Password == currPass
    select x).FirstOrDefault();
    if (userEntity != null )
    {

    userEntity.Password = TxtNwPswd.Text;

    context.SaveChanges();
    }
    else
    {
    lbl_msg.Text = "username or pass is incorrxx";
    //Fail Logic..
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 30, 2020 4:27 AM

All replies

  • User409696431 posted

    What have you tried?   This forum is not for writing your code for you.  Show us what you tried, tell us what it was supposed to do, tell us what happens if it doesn't work, and show any error message you get.

    Wednesday, July 29, 2020 7:04 PM
  • User186310208 posted

    This is working....

    protected void BtnPswd_Click(object sender, EventArgs e)
    {
    using (var context = new WallpaperEntities4())
    {
    var currPass = TxtCrntPswd.Text;
    var newPass = TxtNwPswd.Text;
    var rePass = TxtCnPswd.Text;
    string UserName = Convert.ToString(Session["UserName"]);

    User userEntity = (from x in context.Users
    where x.UserName == UserName
    && x.Password == currPass
    select x).FirstOrDefault();
    if (userEntity != null )
    {

    userEntity.Password = TxtNwPswd.Text;

    context.SaveChanges();
    }
    else
    {
    lbl_msg.Text = "username or pass is incorrxx";
    //Fail Logic..
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 30, 2020 4:27 AM