关于后台验证?,麻烦大家帮我改改代码?

z532264001 2011-05-13 04:45:52

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
});
}
}


麻烦大家帮我修改哈代码?
在跟数据库数据,验证的时候,密码是MD5加密码后的,字符,所以登不进去

<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>
...全文
72 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
子夜__ 2011-05-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ltcszk 的回复:]
麻烦大家帮我修改哈代码?
在跟数据库数据,验证的时候,密码是MD5加密码后的,字符,所以登不进去

你在注册用户时不用md5加密?
[/Quote]
你断点你的密码。跟数据库中查出来的密码想等不想等就可以了。
wocaononame 2011-05-13
  • 打赏
  • 举报
回复
在登录的代码中设置Session,然后再后台其他页面中验证Session是否为空,若为空返回登录页面
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["Admin"] != null)
{
}
else
{
Response.Redirect("Admin_loging.aspx");
}
}
z532264001 2011-05-13
  • 打赏
  • 举报
回复
我要的只是一个管理员,请问,怎么控制这个管理员文件夹
z532264001 2011-05-13
  • 打赏
  • 举报
回复
注册时也 MD5用密码加密,也可以了
不过怎么才能,只有登录后能获得控制权限呢
ltcszk 2011-05-13
  • 打赏
  • 举报
回复

麻烦大家帮我修改哈代码?
在跟数据库数据,验证的时候,密码是MD5加密码后的,字符,所以登不进去

你在注册用户时不用md5加密?
深红龙骑兵 2011-05-13
  • 打赏
  • 举报
回复
[Quote=引用楼主 z532264001 的回复:]
麻烦大家帮我修改哈代码?
在跟数据库数据,验证的时候,密码是MD5加密码后的,字符,所以登不进去

[/Quote]
什么意思?米看懂

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧