当前位置:编程学习 > C#/ASP.NET >>

重新修改密码。。。

很经典
3个文本控件
输入旧密码 输入新密码 重新输入新密码
1个确认按钮

用到数据库连接
密码在数据库里加密过

代码应该怎么写? --------------------编程问答-------------------- up

密码在数据库里加密过 


不懂 --------------------编程问答-------------------- 数据库可以加密密码吗,没听过 --------------------编程问答-------------------- 写错。。。在程序里把密码加密。。。然后再存入数据库的。。。不好意思。。。这个不用理。。。 --------------------编程问答--------------------  protected void ButtonChang_Click(object sender, EventArgs e)
    {
        string loginName = Session["login_name"].ToString();
        string oldpassword = TextBoxOldPassword.Text;
        string newpassword = TextBoxNewPassword.Text;
        string newpassword2 = TextBoxNewPassword2.Text;

        User user = new User();
        user.LoadData(loginName);
            

        if (loginName == "guest" || loginName == "")
        {
            Response.Write("<script>alert(\"对不起,您没有密码可以修改!\");window.location.href='login2.aspx';</script>");
        }

        else
        {
            if (TextBoxOldPassword.Text == "" || TextBoxNewPassword.Text == "" || TextBoxNewPassword2.Text == "")
            {
                if (TextBoxOldPassword.Text == "")
                {
                    Response.Write("<Script Language=JavaScript>alert(\"请输入旧密码!\")</Script>");
                    return;
                }

                if (TextBoxNewPassword.Text == "")
                {
                    Response.Write("<Script Language=JavaScript>alert(\"请输入新密码!\")</Script>");
                    return;
                }

                if (TextBoxNewPassword2.Text == "")
                {
                    Response.Write("<Script Language=JavaScript>alert(\"请输入确认新密码!\")</Script>");
                    return;
                }
            }


            else
            {               
                if (oldpassword == user.Password)
                {
                    if (newpassword2 != newpassword)
                    {
                        Response.Write("<Script Language=JavaScript>alert(\"新密码与确认新密码必须一致!\")</Script>");
                    }
                    else
                    {
                        //连接数据库 
                        SqlConnection conn = new SqlConnection();
                        conn.ConnectionString = "Data Source=name;Database=database;User Id=sa;Pwd=";

                        conn.Open();
                        string strSql = "update [table] set [字段] =" + SqlStringFormat.GetQuotedString(TextBoxNewPassword.Text) + " where [id] =" + SqlStringFormat.GetQuotedString(id);
                        SqlCommand cmd = new SqlCommand(strSql, conn);
                       
                        cmd.ExecuteNonQuery();
                        conn.Close();

                        Response.Write("<script>alert(\"恭喜您,密码修改成功!\");window.location.href='login2.aspx';</script>");
                      
                    }

                }

                else
                {
                    Response.Write("<Script Language=JavaScript>alert(\"您输入的旧密码错误,请重新输入密码!\")</Script>");
                }
            }
        }
    } --------------------编程问答-------------------- 思路是这样的!给你参考参考
数据库:SQL
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,