更改用户密码 [英] change user password
本文介绍了更改用户密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用C#和sql server在visual studio中开发一个Web应用程序。
我想创建一个用户应该更改密码的页面。
i尝试过这但没有成功
请帮我找到错误
命名空间 Csharp
{
public partial class 更改:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgs e)
{
if (会话[ new]!= null )
{
txt_username.Disabled = true ;
txt_username.Value =会话[ 用户名]。ToString();
}
}
受保护 void btn_submit_Click( object sender,EventArgs e)
{
if (txt_newpass.Value.Length < 6 )
{
回复.Write( < script language = Javascript> .....!< / script>);
}
if (txt_newpass.Value!= txt_newpass2.Value)
{
Response.Write ( < script language = Javascript> ......!< / script> );
}
string pass;
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings [ ConnectionStringusersregj跨度>]的ConnectionString)。
conn.Open();
string querysel = 从UserName =' + Session [ username中选择* >]。ToString()+ ';
SqlCommand kom = new SqlCommand(querysel,conn);
SqlDataAdapter sqlDa = new SqlDataAdapter(kom);
sqlDa.Fill(dt);
if (dt.Rows.Count> 0)
{
pass = dt.Rows [ 0 ] [ 密码]。ToString() ;
if (pass == txt_password.Value)
{
string cod = UPDATE用户设置密码=' + txt_newpass.Value + '其中UserName =' + Session [ new]。ToString()+ ' 跨度>;
SqlCommand cmd = new SqlCommand(cod,conn);
cmd.ExecuteNonQuery();
}
else
{
Response.Write( < script language = Javascript> Old pass is incorredt< / script>);
}
}
conn.Close();
}
}
}
解决方案
在开始修复之前,改变方式你处理它们!
永远不要以明文形式存储密码 - 这是一个主要的安全风险。有关如何在此处执行此操作的信息:密码存储:如何做到这一点。 [ ^ ]
i am developing a web app in visual studio using C# and sql server.
I want to create a page that the user should change his password.
i have tried this but no successs
pls help me find the error
namespace Csharp
{
public partial class change : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["new"] != null)
{
txt_username.Disabled = true;
txt_username.Value = Session["username"].ToString();
}
}
protected void btn_submit_Click(object sender, EventArgs e)
{
if (txt_newpass.Value.Length < 6)
{
Response.Write("<script language=Javascript>.....!</script>");
}
if (txt_newpass.Value != txt_newpass2.Value)
{
Response.Write("<script language=Javascript>......!</script>");
}
string pass;
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionStringusersregj"].ConnectionString);
conn.Open();
string querysel = "Select * from Users where UserName='" + Session["username"].ToString() + "' ";
SqlCommand kom = new SqlCommand(querysel, conn);
SqlDataAdapter sqlDa = new SqlDataAdapter(kom);
sqlDa.Fill(dt);
if(dt.Rows.Count>0)
{
pass = dt.Rows[0]["Password"].ToString();
if (pass == txt_password.Value)
{
string cod = "UPDATE Users set Password='"+ txt_newpass.Value +"' where UserName='" + Session["new"].ToString() + "'";
SqlCommand cmd = new SqlCommand(cod, conn);
cmd.ExecuteNonQuery();
}
else
{
Response.Write("<script language=Javascript>Old pass is incorredt</script>");
}
}
conn.Close();
}
}
}
解决方案
Before you even start to fix that, change the way you handle them!
Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]
这篇关于更改用户密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文