用户更改时,密码不会在数据库中更新 [英] Password is not updated in database when changed by user
本文介绍了用户更改时,密码不会在数据库中更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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;
}
}
推荐答案
为什么让自己感到困惑。为什么不用简单的代码,使用这个算法:
点击你的按钮
从用户名=登录的表中选择和输入密码用户
if(pasword.text ==|| confermpass ==)
{
输入通行证
}
其他
{
upadate密码,其中用户名=登录用户
}
i希望你很容易:)
why are you confusing yourself. why dont you use simple code, use this algo:
on your button click
select and password from table where user name=logged in user
if (pasword.text=="" || confermpass =="")
{
enter pass
}
else
{
upadate password where user name=logged in user
}
i hope it will be very easy for you :)
这篇关于用户更改时,密码不会在数据库中更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文