asp.net网站设计,忘记密码功能的代码实现?

来源:互联网 发布:淘宝详情页设计软件 编辑:程序博客网 时间:2024/05/23 16:51
            string userID = this.userID.Text.Trim();            string newpwd = this.newpwd.Text.Trim();//新密码             string newpwda = this.newpwda.Text.Trim();//确认新密码 
            //数据库连接
            string conn = "Data Source=KoBe-PC;Initial Catalog=zujuan;Integrated Security=true";            SqlConnection con = new SqlConnection(conn);
 
            //打开数据库
            con.Open();            SqlCommand cmmd = new SqlCommand("select   userID   from   [user]   where   userID= ' " + this.userID.Text + " ' ", con);
            //读取数据库里的数据
            SqlDataReader dr = cmmd.ExecuteReader();            if (dr.Read ())            {               
//取得数据库的数据的值,并进行判断,是否存在此用户
                if (dr["userID"].ToString().ToLower() != "")                {
//判断文本框里的值是否为空
                    if (this.newpwd.Text.Trim() == "" && this.newpwda.Text.Trim() == "")                    {
//lable用于显示提示信息
                        this.Label2.Text = "不能为空";                        this.Label2.Visible = true;                        this.Label3.Text = "不能为空";                        this.Label3.Visible = true;                        this.Label4.Visible = false;                    }
//判断两次输入密码是否一致
                    else if (this.newpwd.Text.Trim() != this.newpwda.Text.Trim())                    {                        //Response.Write("<script language='javascript'>alert('两次输入密码不一致,请从新输入!');</script>");                        this.Label4.Text = "两次输入密码不一致,请从新输入!";                        this.Label4.Visible = true;                        this.newpwd.Text = "";                        this.newpwda.Text = "";                        this.Label2.Visible = false ;                        this.Label3.Visible = false;                    }
////判断与原密码是否相同
                //    else if (dr["userID"].ToString().ToLower() == this.userID.Text.Trim())                //   {                //        this.Label5.Text = "与原密码相同,请从新输入!";                //        this.Label5.Visible = true;                //    }                    else                    {
                        con.Close();
//修改数据库里的数据
                        SqlCommand cmd = new SqlCommand("update   [user]   set   passWord= ' " + this.newpwd.Text.Trim() + " '   where   userID= '" + userID + "'", con);                        con.Open();                        cmd.ExecuteNonQuery();                        con.Close();                        Response.Write("<script language='javascript'>alert('密码修改成功,请重新登录!');window.location='Login.aspx';</script>");                    }                }            }            else            {                Response.Write("<script language=javascript>alert('无该用户!')</script>");            }


其中判断与密码相同那段代码可以不用。