using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using wormstrdo;

public partial class wormadmin_login : System.Web.UI.Page
{
    SqlConnection one = conn.sqlconn();   //建立连接数据库对象
    sqloper sqloper = new sqloper();
    strreplace str = new strreplace();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (Page.IsValid)
        {
                if (this.btcheck.Text == Request.Cookies["vCode"].Value)
                {
                    //过滤字符串
                    string ad = str.txtstr(btad.Text);
                    string pw = str.txtstr(btpw.Text);
                    //End
                    string sql = "select * from superadmin";
                    SqlCommand cmd = new SqlCommand(sql, one);
                    try
                    {
                        one.Open();
                        SqlDataReader rs = cmd.ExecuteReader();
                        if (rs.Read())
                        {
                            //Response.Write(Encryption.pwencrypt(ad,1));
                            //Response.Write(Encryption.Decrypt(rs["ad"].ToString()));
                            if (ad == rs["ad"].ToString() && Encryption.pwencrypt(pw, 1) == rs["pw"].ToString())
                            {
                                Session["superad"] = ad;
                                Session["superpw"] = pw;
                                Session["superlei"] = "后台管理员";
                                Response.Redirect("main.aspx");
                            }
                            else
                            {
                                ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('对不起！用户名或密码有误！');</script>");
                            }
                        }
                        else
                        {
                            ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('对不起！用户名或密码有误！');</script>");
                        }
                        rs.Dispose();
                    }
                    catch (System.Exception ee)
                    {
                        Response.Write(ee.Message.ToString());
                    }
                    finally
                    {
                        cmd.Dispose();
                        one.Close();
                    }
                }
                else
                {
                    ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('验证码错误,请重新输入！');</script>");
                }
            
           
        }
    }
}
