The project requires users to modify the Servu password themselves. SERVU can access the Access\mysql\sqlserver database through ODBC. We can modify it directly by creating the Web.
But the problem is, the password is encrypted ... Find out how to encrypt the. NET version by searching online ... Self-verification No problem ...
The following is a simple test code (quote others blog)
SERVU Encryption:
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 = "Ph47d991ccdce74cc5171ea b95c2446598 ";
String Strpasswordfronttwochars;
if (Strpassword.length > 2)
{
//read random letters contained in the password
Strpasswordfronttwochars = strpassword.substring (0, 2);
if (Createcrypassword (Strpasswordfronttwochars, "gzf") = = strpassword)
{//password conforms to
Response.Write ("true");
}
Else
{//password does not match
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>
Generate random strings with a string length of 2
</summary>
<returns></returns>
public string getrandomstring ()
{
String strreturn = "";
Random ran = new random ();
Strreturn + = Convert.tochar (ran. Next (+) + ' a '). ToString ();
Strreturn + = Convert.tochar (ran. Next (+) + ' a '). ToString ();
return strreturn;
}
Generates an encrypted password from the specified random letter and login password
public string Createcrypassword (string strfrontchars, String strpassword)
{
return strfrontchars + MD5 (strfrontchars + strpassword). ToUpper (). Trim ();
}
/**/
<summary>
"Change Password" Click event to modify the password in this event
</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 = "User name cannot be empty";
Return
//}
Determine if the password input is the same two times
if (txtnewpassword.text! = txtconfirmpassword.text)
//{
controlmessage.innerhtml = "Two times the password entered is inconsistent, please re-enter";
Return
//}
IniFile ini = new IniFile (_strservudaemonpath);
String strsectionvalue = "user=" + struserid.trim () + "1";
Determines whether the user exists by reading the homedir of the specified user
if (INI. ReadString (Strsectionvalue, "Homedir", "") = = = "")
//{
controlmessage.innerhtml = "The specified user does not exist";
Return
//}
Start judging if the password is correct
String strpassword = ini. ReadString (Strsectionvalue, "Password", "" ");
}
}
}
Modify SERVU Database Password Servu encryption method