標籤:
項目要求可以有使用者自行修改servu密碼。servu可以通過odbc訪問access\mysql\sqlserver資料庫。我們直接通過建立web來修改就可以了。
不過問題來了,密碼是加密的...通過網上搜尋找到了.net版本的加密方式...自己驗證沒問題...
下面貼出簡單的測試代碼(引用他人部落格)
servu加密:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Web.Security;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string strPassword = "ph47D991CCDCE74CC5171EAB95C2446598";
string strPasswordFrontTwoChars;
if (strPassword.Length > 2)
{
//讀取密碼中包含的隨機字母
strPasswordFrontTwoChars = strPassword.Substring(0, 2);
if (CreateCryPassword(strPasswordFrontTwoChars, "gzf") == strPassword)
{//密碼符合
Response.Write("true");
}
else
{//密碼不符
Response.Write("false");
}
}
}
public String MD5(String strContent)
{
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(strContent);
bytes = md5.ComputeHash(bytes);
md5.Clear();
string ret = "";
for (int i = 0; i < bytes.Length; i++)
{
ret += Convert.ToString(bytes[i], 16).PadLeft(2, ‘0‘);
}
return ret.PadLeft(32, ‘0‘).ToUpper();
}
/**/
/// <summary>
/// 產生隨便字串,字串長度為2
/// </summary>
/// <returns></returns>
public string GetRandomString()
{
string strReturn = "";
Random ran = new Random();
strReturn += Convert.ToChar(ran.Next(26) + ‘a‘).ToString();
strReturn += Convert.ToChar(ran.Next(26) + ‘a‘).ToString();
return strReturn;
}
//由指定的隨機字母和登入密碼產生加密後的密碼
public string CreateCryPassword(string strFrontChars, string strPassword)
{
return strFrontChars + MD5(strFrontChars + strPassword).ToUpper().Trim();
}
/**/
/// <summary>
/// “修改密碼”的點擊事件,在此事件中對密碼進行修改
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnModifyPwd_Click(object sender, System.EventArgs e)
{
//string strUserID = txtLoginID.Text;
//if (strUserID == String.Empty)
//{
// controlMessage.InnerHtml = "使用者名稱不可為空";
// return;
//}
////判斷兩次密碼輸入是否相同
//if (txtNewPassword.Text != txtConfirmPassword.Text)
//{
// controlMessage.InnerHtml = "兩次輸入的密碼不一致,請重新輸入";
// return;
//}
//IniFile ini = new IniFile(_strServUDaemonPath);
//string strSectionValue = "USER=" + strUserID.Trim() + "1";
////通過讀取指定使用者的HomeDir來確定是否存在該使用者
//if (ini.ReadString(strSectionValue, "HomeDir", "") == "")
//{
// controlMessage.InnerHtml = "指定的使用者不存在";
// return;
//}
//開始判斷密碼是否正確
// string strPassword = ini.ReadString(strSectionValue, "Password", "");
}
}
}
修改servu資料庫密碼 servu加密方式