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 Spaces;

public partial class Manage_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!this.IsPostBack)
            BindImg();


    }

    void BindImg()
    {
       
        this.Image1.ImageUrl = string.Format("{0}/Include/VerifyCode.aspx", Globals.ApplicationPath);

    }
    protected void ibtnLogin_Click(object sender, ImageClickEventArgs e)
    {
      
        string username = Account.Text;
        string password = Password.Text;
        string code = verifyCode.Text;

        if (Session["Verify"] == null || Session["Verify"].ToString() != code)
        {

            string script = "<script>alert('请输入正确的验证码！');history.go(-1);</script>";
            this.RegisterStartupScript("verifyErr", script);
            return;
        }
        if (SiteTools.IsLoginDisallowed(username))
        {
            SpacesContext.RedirectToMessage(MessageType.LoginBanned);
        }
        password = Des.Encrypt(password, "xiaoxiao");
        string sql = string.Format("SELECT * FROM  tbl_Admin  where  Username ='{0}'",username);
        DataRow dr =SpacesDataProvider.Instance().GetDataRow(sql);
       // Response.Write(password + "<br>" + dr["Password"].ToString());
        if (dr == null || dr["password"] == DBNull.Value)
        {
            string script = "<script>alert('用户不存在！');history.go(-1);</script>";
            this.RegisterStartupScript("verifyErr", script);
            return;
        }
        string pass1=dr["Password"].ToString().Trim();
       if (password != pass1)
        {
            string script = "<script>alert('密码错误！');history.go(-1);</script>";
            this.RegisterStartupScript("verifyErr", script);
            return;
        }
        Session["Admin"] = username;
        Response.Redirect("Main.aspx");
    }
}
