每天早上的代码
namespace X
{
public class Login:System.Web.UI.Page
{
protected string PreUserName{get;set;}
protected string Js{get;set;}
public string Load_Page(object sender,EvevtAges e)
{
if(!IsPostBack)
{
PreUserName=Request.Cookies["txtusername"]==null?string.Empty:Request.Cookies["txtLoginName"].Value;
}
else
{
PreUserName=Request["txtLoginName"];
}
}
public string btnLoginClick(object sender,ImageButtonEventAges)
{
string sendCode=Session["ValidDateCode"]==null?string.Empty:Session["ValidDateCode"].ToString();
string reviceCode=Request["txtCode"];
if(!sendCode.Equals(reviceCode))
{
Js="<script>alert('验证码错误')</script>"
return ;
}
string strUsername=Request["txtLoginName"];
string StrPwd=Request["txtPassword"];
BLL.CZBK_user userInfoservice=new CZBK_user();
Model.CZBK_user user=userInfoservice.GetModelList(strUserName,strPassword);
if(user==null)
{
Js="<script>alert('验证码和密码错误')</script>";
return ;
}
Session["Loginuser"]=user;
string name=Request["txtLogin"];
if(!string.Empty(name))
{
Response.Cookies["userName"].value=name;
//删除Cookies;
Response.Cookies["userName"].Expirse=DateTime.Now.AddDays(7);
}
Response.Redirct("Admin.aspx");
}
}
}
//MD5
public class Md5
{
public string StringFormString(string str)
{
MD5 md5=MD5.Create();
StringBuilder sb=new StringBuilder();
byte[]bytes=System.Text.Enconding.UTF8.GetBytes[str];
byte[]bys=md5.ComputerHash(bytes);
for(int i=0;i<bys.Length;i++)
{
sb.Append(bys[i].ToString("x2"));
}
md5.Clear();
return sb.ToString();
}
public string StringFromFile(string path)
{
MD5 md5=MD5.Create();
using(FileStream fs=File.OpenRead(path))
{
StringBuilder sb=new StringBuilder();
byte[]bys=md5.ComputerHash(fs);
for(int i=0;i<bys.Length;i++)
{
sb.Append(bys[i].ToString("x2"));
}
md5.Clear();
return sb.ToString();
}
}
}