标签:
项目要求可以有用户自行修改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", "");
}
}
}
标签:
原文地址:http://www.cnblogs.com/guozefeng/p/4479776.html