59 }
60
61 IniFile ini = new IniFile( _strServUDaemonPath );
62 string strSectionValue = "USER=" strUserID.Trim() "|1";
63
64 //通过读取指定用户的HomeDir来确定是否存在该用户
65 if( ini.ReadString( strSectionValue, "HomeDir", "" ) == "" )
66 {
67 controlMessage.InnerHtml = "指定的用户不存在";
68 return;
69 }
70
71 //开始判断密码是否正确
72 string strPassword = ini.ReadString( strSectionValue, "Password", "" );
73
74 string strPasswordFrontTwoChars;
75 bool bPasswordRight = false;
76 if( strPassword.Length > 2 )
77 {
78 //读取密码中包含的随机字母
79 strPasswordFrontTwoChars = strPassword.Substring( 0, 2 );
80 if( CreateCryPassword( strPasswordFrontTwoChars, txtOldPassword.Text ) == strPassword )
81 {//密码符合
82 bPasswordRight = true;
83 }
84 else
85 {//密码不符
86 bPasswordRight = false;
87 }
88 }
89 else if( strPassword == txtOldPassword.Text ) //原密码为空
90 {
91 bPasswordRight = true;
92 }
93 else
94 {
95 bPasswordRight = false;
96 }
97
98 if( bPasswordRight )
99 {
100 //密码正确,写入新的密码,并设置自动加载新的设置,以便下一次更改时仍有效
101 ini.WriteString( strSectionValue, "Password", CreateCryPassword( GetRandomString(), txtNewPassword.Text ) );
102 controlMessage.InnerHtml = "完成密码修改";
103 }
104 else
105 {
106 controlMessage.InnerHtml = "原密码错误";
107 }
108
109 }
以上代码中的_strServUDaemonPath变量用于保存ServUDaemon.ini文件所在的路径,该值可以在PageLoad事件中通过Web.Config设置取得。
但事情并没有就此结束。经过测试,发现在存在一个严重的问题:修改密码后只有重启Serv-U才能使修改后的密码生效。那不是等于没什么用嘛,管理员总不可能没事老在那里重启服务器来使密码修改生效吧。
再次回来Serv-U的官方知识库,查到了如下一条内容:
Manually Updating the ServUDaemon.ini File
Whenever changes are made directly to the ServUDaemon.ini file, add the following line under the Global area in the INI file.
ReloadSettings=True
Serv-U regularly checks the INI file for this setting. If it is present, Serv-U will refresh all stored settings for every domain on the server. This allows Serv-U to recognize the changes without having to be restarted.
After Serv-U loads the changes, it removes the "ReloadSettings=True" entry. This allows you to enter it again next time any changes are made.
也就是说,只要在INI文件的GLOBAL节添加键ReloadSettings并设置它的值为True便可以实现修改密码后自动更新了。于是只要修改原代码,在101行和102行之间插入如下一句代码即可:
ini.WriteString( "GLOBAL", "ReloadSettings", "True" );
到这里,一个在线修改Serv-U密码的网页就全部完成了。
程序中的IniFile是一个封装了API对INI文件操作的类,仅需要实现对字符串的读取和写入即可。
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




