if(!File.Exists("c:\\user.ini"))
{
StreamWriter sw = new StreamWriter("c:\\user.ini");
string strName = tbName.Text;
string strPass = tbPass.Text;
string strEncryPass = System.Web.Security.FormsAuthentication.
HashPasswordForStoringInConfigFile(strPass,"md5");
sw.WriteLine(strName);
sw.WriteLine(strEncryPass);
sw.Close();
// 資料加密函數System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strPass,"md5")
}
else
{
//從user.ini中讀出儲存的使用者名稱稱和密碼,進行比較
StreamReader sr = new StreamReader("c:\\user.ini");
string strSaveName = sr.ReadLine();
string strSavePass = sr.ReadLine();
sr.Close();
string strInputPass = System.Web.Security.FormsAuthentication
.HashPasswordForStoringInConfigFile(tbPass.Text,"md5");
if(strSaveName!=tbName.Text||strSavePass!=strInputPass)
{
Response.Write("使用者名稱稱或密碼錯誤!");
mainPanel.Visible = false;
}
else
Response.Write("<script language = javascript>alert('成功登入!')</script>");
}
資料加密
方法一: