用C#寫一個類,實作輸入一個字元串,傳回一個MD5值的調用
public static string GetMD5(string sDataIn)
{
MD5CryptoServiceProvider md5 = newMD5CryptoServiceProvider();
byte[] bytValue, bytHash;
bytValue =System.Text.Encoding.UTF8.GetBytes(sDataIn);
bytHash =md5.ComputeHash(bytValue);
md5.Clear();
string sTemp = "";
for (inti = 0; i < bytHash.Length; i++)
{
sTemp+= bytHash[i].ToString("X").PadLeft(2, '0');
}
return sTemp.ToLower();
}
實驗步驟:
建資料庫。呼叫中心項目預設主鍵都用Guid。
Id、UserName、Password
手工加一條資料,用程式算出來123456的md5手工填到資料庫中。
建立一個DataSet,增加一個GetDataByUserName方法,
select * from T_Users where UserName=@UserName
登入的時候計算使用者輸入密碼的md5值,與資料庫中的md5值比較。注意使用者名不存在等這樣的細節問題。暫時不用寫登陸次數過多禁用的功能。
強類型DataSet放到DAL檔案夾中。
Application.Exit();//WinForm中退出程式的辦法
本文轉自蓬萊仙羽51CTO部落格,原文連結:http://blog.51cto.com/dingxiaowei/1366621,如需轉載請自行聯系原作者