ASP.NET OA 开发笔记 Copyrigh@2007 fred-liu@qq.com
<HTML>
<HEAD>
<title>系统登录</title>
...
<script language="javascript" src="../md5.js" type="text/javascript"></script>
</HEAD>
<BODY bgColor="#c1e0fd" ">
<FORM id="userpass" onsubmit="password.value =hex_md5(password.value)" method="post" runat="server">
...
其中<script language="javascript" src="../md5.js" type="text/javascript"></script>的作用是把 md5 加密文件引用到文
件中,然后程序就可以调用了。在 FORM 里面添加是当网页提交时,就对密码进行加密后再把值传递过去,
password.value 是密码框对应的值。
2. userpass.cs 代码;
页面载入的代码:
private void Page_Load(object sender, System.EventArgs e)
{
if (Session["userID"]!=null)
{
Session["userID"] =null;
System.Web.Security.FormsAuthentication.SignOut();
return ;
}
this.lMsg.Text = "";
}
判断 Session["userID"]是为防止从其他页面转到登录界面时,用户信息还没清除,导致信息泄密。
用户登录验证代码:
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
OI.DatabaseOper.DatabaseConnect dc=new DatabaseConnect();
string userID=OI.Modules.String.GenSafeChars(UserName.Text .Trim ());
string passWord=OI.Modules.String.GenSafeChars(password.Text .Trim ());
System.Data.DataSet oDataSet=dc.getBinding("select OPERID,Name from Oper_Table where OPERID='"+userID +"'
and Pwd='"+ passWord +"'and state=0","ttt");
if(oDataSet.Tables[0].Rows.Count>0)
{
Session["UserName"]=oDataSet.Tables[0].Rows[0][1].ToString();
Session["userID"]=userID;
Session["passWord"]=passWord;
string address=Request.UserHostAddress ;
OI.desktop .onlineUser adduser=new OI.desktop.onlineUser ();
string sql="update Oper_Table set LogTime = GetDate(), ";
sql +=" LogIP = '"+address+"' where OPERID ='"+userID+"' ";