62,047
社区成员
发帖
与我相关
我的任务
分享
public static string EncryptionMD5(string password)
{
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] mima = new byte[16];
System.Text.ASCIIEncoding asc = new System.Text.ASCIIEncoding();
mima = md5.ComputeHash(asc.GetBytes(password));
return Convert.ToBase64String(mima);
}
protected void Page_Load(object sender, EventArgs e)
{
}
public bool checkLogin(string username, string password)
{
string strConnection;
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;";
strConnection += "Data Source=";
strConnection += MapPath("../App_Data/game.mdb;");
strConnection += "Jet OLEDB:Database Password=zeng198822!@#";
OleDbConnection objConnection = new OleDbConnection(strConnection);
objConnection.Open();
OleDbCommand cmd = new OleDbCommand("select name,pwd from guanliyuan where name='"+username+"' and pwd='"+password+"'" , objConnection);
OleDbDataReader dr = cmd.ExecuteReader();
//OleDbParameter[] param = new OleDbParameter[]
//{
if (dr.Read())
{
return true;
}
else
{
return false;
}
}
protected void BtnLogin_Click(object sender, AjaxEventArgs e)
{
string username = txtUserName.Text.Trim();
string password = this.txtPassWord.Text;
//MD5加密密码
string md5_pass = EncryptionMD5(password);
if (checkLogin(username, md5_pass))
{
FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, username,
DateTime.Now, DateTime.Now.AddMinutes(30), false, "/"); //建立身份验证票对象
string HashTicket = FormsAuthentication.Encrypt(Ticket); //加密序列化验证票为字符串
HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket);
//生成Cookie
Context.Response.Cookies.Add(UserCookie); //输出Cookie
//Context.Response.Redirect(Context.Request["ReturnUrl"]); // 重定向到用户申请的初始页面
Response.Redirect("ViewPort.aspx");
}
else
{
Ext.Msg.Show(new MessageBox.Config
{
Title = "返回提示",
Message = "用户名或密码错误,请确认!",
Icon = MessageBox.Icon.ERROR,
Buttons = MessageBox.Button.OK
});
}
}
<body>
<form id="form1" runat="server">
<div>
<ext:ScriptManager ID="ScriptManager1" runat="server">
</ext:ScriptManager>
<ext:Window ID="Window1" runat="server" Width="350" ButtonAlign="Right" BodyStyle="padding:20px;"
Height="200" Title="登录后台管理" Draggable="false" Closable="false" Maximizable="false"
Modal="true" Icon="UserGo" Resizable="false">
<Body>
<ext:FormPanel ID="login" runat="server" Frame="true" BodyStyle="padding:10px;">
<Body>
<ext:FormLayout ID="FormLayout1" runat="server" LabelWidth="60">
<ext:Anchor Horizontal="100%">
<ext:TextField ID="txtUserName" runat="server" FieldLabel="用户名" AllowBlank="false"
BlankText="请输入管理员帐号!">
</ext:TextField>
</ext:Anchor>
<ext:Anchor Horizontal="100%">
<ext:TextField ID="txtPassWord" InputType="Password" runat="server" FieldLabel="密 码"
AllowBlank="false" BlankText="请输入正确的管理员口令!">
</ext:TextField>
</ext:Anchor>
</ext:FormLayout>
</Body>
</ext:FormPanel>
</Body>
<Buttons>
<ext:Button ID="btnLogin" runat="server" Text="登录" Type="Submit" Icon="ServerGo">
<AjaxEvents>
<Click OnEvent="BtnLogin_Click" Before="return login.getForm().isValid();">
<EventMask ShowMask="true" Msg="正在验证登录,请稍候..." />
</Click>
</AjaxEvents>
</ext:Button>
<ext:Button ID="Button2" runat="server" Text="重置" Type="Reset" Icon="ArrowRefreshSmall">
<Listeners>
<Click Handler="login.getForm().reset();" />
</Listeners>
</ext:Button>
</Buttons>
</ext:Window>
</div>
</form>
</body>
<location >
<system.web>
<authentication mode="Forms">
<forms loginUrl= "Login.aspx" name=".ASPXAUTH" timeout="30" path= "/"/>
</authentication>
<httpModules>
<add name="AjaxRequestModule" type="Coolite.Ext.Web.AjaxRequestModule, Coolite.Ext.Web" />
</httpModules>
<httpHandlers>
<add path="*/coolite.axd" verb="*" type="Coolite.Ext.Web.ResourceManager"
validate="false" />
</httpHandlers>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation>
</system.web>
</location>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["Admin"] != null)
{
}
else
{
Response.Redirect("Admin_loging.aspx");
}
}