网络孤魂
一切都还是那么的迷茫啊。。。。。。。
导航
博客园
首页
新随笔
联系
订阅
管理
统计
随笔 - 10
文章 - 0
评论 - 47
引用 - 0
公告
待写。。。。。
与我联系
发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
(3)
给我留言
查看留言
随笔分类
.NET编程(WebForm)(5)
(rss)
.NET编程(WinForm)(1)
(rss)
FirdBird数据库相关
(rss)
开发随想(1)
(rss)
心情记录(1)
(rss)
随笔档案
2006年6月 (1)
2006年3月 (1)
2006年1月 (2)
2005年11月 (2)
2005年9月 (2)
2005年8月 (2)
最新评论
1. re: FCKeditor应用小记--起步篇
不是我需要的内容,不过还是给你顶一下!
--VisualStudio
阅读排行榜
1. FCKeditor应用小记--起步篇(4948)
2. 用正则表达式判断时间是否合法(2468)
3. 都是编码惹的祸!(1052)
4. 为Serv-U提供在线修改密码功能(900)
5. 有关kinbor提出的DataGrid刷新问题续(419)
评论排行榜
1. FCKeditor应用小记--起步篇(19)
2. 都是编码惹的祸!(11)
3. 用正则表达式判断时间是否合法(6)
4. 为Serv-U提供在线修改密码功能(6)
5. 开张试发(2)
为Serv-U提供在线修改密码功能
由于日常工作的需要,单位使用Serv-U架设了一个FTP服务器,可是自从接手之后发现存在着一个非常严重的问题,这个FTP服务器是对外公开的,居然很多用户都没有设置密码。如果强制要求所有人设置密码又必须在服务器上设,这样岂不是要所有人都把自己的密码告诉管理员吗,毕竟很多人习惯于用同一个密码的。怎么办呢?最好的办法当然是能够提供一个Web页面来提供密码的修改功能。
说干就干,在网上查了一下,有一种方法是使用Serv-U自身提供的ODBC功能,用数据库来存储密码,通过直接对数据库进行操作来实现密码的修改功能,但经过考试这种方法并不太可行。因为这个FTP服务器已经运行了一年之久,里面已有将近六十个用户,要将这些用户从Ini文件移植到数据库出现错误的几率还是比较高的,还不如直接对INI文件进行操作来得干脆。
首先是要搞清楚Serv-U的用户信息在INI文件中是如何保存的,密码又是如何加密的。INI文件的结构比较简单,修改密码的话只要找到以[User=@UserID|1]节,并修改其下的Password键的值即可。@UserID指的是用户的登录ID。
1
[
GLOBAL
]
2
Version
=
6.1.0.5
3
PacketTimeOut
=
300
4
5
6
7
[
Domain1
]
8
User1
=
9
User2
=
10
User3
=
11
12
13
14
[
USER=abc|1
]
15
Password
=
niE383DC3710266ECAE04A6B3A18A2966D
16
HomeDir
=
D:\
17
AlwaysAllowLogin
=
1
18
ChangePassword
=
1
19
TimeOut
=
600
20
Note1
=
"
Wizard generated account
"
21
Access1
=
D:\
22
23
用户密码的加密方法可以在Ser-U官方网站的知识库查到
http://rhinosoft.com/KBArticle.asp?RefNo=1177&prod=su
Manually Entering Encrypted Passwords into the ServUDaemon.ini File
To generate an encrypted password, first two random characters (the 'salt' - in the range a..z, A..Z) are added to the beginning of the clear-text password. This is then hashed using MD5 and the resulting hash is hex-encoded. The result of this is written as plain-text starting with the 2 salt characters followed by the hex-encoded hash.
For a user account in the .ini file, this will look like:
Password=cb644FB1F31184F8D3D169B54B3D46AB1A
The salt is the string "cb", the MD5 hash is "644FB1F31184F8D3D169B54B3D46AB1A".
When verifying a user's password, Serv-U will do the same. It parses the salt from the user's stored password (ie. "cb" in this case), prepends it the password the user sent to it by the client, MD5 hashes it, and compares the result with the stored hash. If the values are equal, then the entered password is correct.
加密的方法也就是随机生成两个字母,然后将字母和密码进行拼接,再求它们的MD5值,最后将随机字母放在MD5值的前面便是加密后的密码。
接下来就可以根据以上的分析编写程序来实现在线修改了。
1
/**/
///
<summary>
2
///
获取指定字符串的MD5值
3
///
</summary>
4
///
<param name="strContent"></param>
5
///
<returns></returns>
6
public
String MD5( String strContent )
7
{
8
System.Security.Cryptography.MD5 md5
=
new
System.Security.Cryptography.MD5CryptoServiceProvider();
9
byte
[] bytes
=
System.Text.Encoding.UTF8.GetBytes( strContent );
10
bytes
=
md5.ComputeHash( bytes );
11
md5.Clear();
12
string
ret
=
""
;
13
for
(
int
i
=
0
; i
<
bytes.Length ; i
++
)
14
{
15
ret
+=
Convert.ToString(bytes[i],
16
).PadLeft(
2
,
'
0
'
);
16
}
17
return
ret.PadLeft(
32
,
'
0
'
).ToUpper();
18
}
19
20
21
/**/
///
<summary>
22
///
生成随便字符串,字符串长度为2
23
///
</summary>
24
///
<returns></returns>
25
public
string
GetRandomString()
26
{
27
string
strReturn
=
""
;
28
Random ran
=
new
Random();
29
strReturn
+=
Convert.ToChar( ran.Next(
26
)
+
'
a
'
).ToString();
30
strReturn
+=
Convert.ToChar( ran.Next(
26
)
+
'
a
'
).ToString();
31
return
strReturn;
32
}
33
34
//
由指定的随机字母和登录密码生成加密后的密码
35
public
string
CreateCryPassword(
string
strFrontChars,
string
strPassword )
36
{
37
return
strFrontChars
+
MD5( strFrontChars
+
strPassword ).ToUpper().Trim();
38
}
39
40
/**/
///
<summary>
41
///
“修改密码”的点击事件,在此事件中对密码进行修改
42
///
</summary>
43
///
<param name="sender"></param>
44
///
<param name="e"></param>
45
private
void
btnModifyPwd_Click(
object
sender, System.EventArgs e)
46
{
47
string
strUserID
=
txtLoginID.Text;
48
if
( strUserID
==
String.Empty )
49
{
50
controlMessage.InnerHtml
=
"
用户名不能为空
"
;
51
return
;
52
}
53
54
//
判断两次密码输入是否相同
55
if
( txtNewPassword.Text
!=
txtConfirmPassword.Text )
56
{
57
controlMessage.InnerHtml
=
"
两次输入的密码不一致,请重新输入
"
;
58
return
;
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文件操作的类,仅需要实现对字符串的读取和写入即可。
posted on 2006-01-15 13:32
网络孤魂
阅读(900)
评论(6)
编辑
收藏
网摘
所属分类:
.NET编程(WebForm)
Comments
#1楼
[
楼主
]
ranfu
对89到96的代码进行了修改,原来的代码缺少了对空密码的处理,现已可以正常使用
Posted @ 2006-01-15 17:29
回复
引用
查看
#2楼
Goodspeed
Serv_u可以通过数据库保存信息.
密码可以通过ftp命令来修改.
Posted @ 2006-01-15 18:32
回复
引用
查看
#3楼
[
楼主
]
ranfu
这个知道,但有时使用数据库保存必须进行大量的用户数据迁移,而使用Ftp命令修改并不是所有人都会用的
Posted @ 2006-01-15 20:23
回复
引用
查看
#4楼
笑笑游戏
有个问题就是 这个程序能否访问ServUDaemon.ini这个文件?
会不会出现没有权限的问题呀?
因为ServUDaemon.ini 不会在WEB目录下,这样就会有没有权限,无法访问的问题!
Posted @ 2006-01-16 08:49
回复
引用
查看
#5楼
[
楼主
]
ranfu
可以的啊,这个程序我测试过的,而且现在还在用呢
Posted @ 2006-01-16 18:12
回复
引用
查看
#6楼
yadjxx [未注册用户]
能否提供出你的所有文件打个包让我下载一下!谢谢
Posted @ 2006-02-26 14:55
回复
引用
图书专题
新用户注册
刷新评论列表
标题
姓名
主页
Email
(博主才能看到)
验证码
*
看不清,换一张
[
登录
][
注册
]
内容(请不要发表任何与政治相关的内容)
网站首页
新闻频道
社区
小组
博问
网摘
人才
找找看
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
该文被作者在 2006-01-15 17:27 编辑过
Google站内搜索
[推荐职位]上海盛大网络招聘架构师
China-pub 计算机图书网上专卖店!6.5万品种 2-8折!
近千种 9-95 新二手计算图书火热销售中!
开发者征途系统新作:《设计模式——基于C#的工程化实现及扩展》
相关文章:
相关链接:
所属分类的其他文章:
开始架设Community Server2
为Serv-U提供在线修改密码功能
都是编码惹的祸!
FCKeditor应用小记--起步篇
用正则表达式判断时间是否合法
最新IT新闻:
国内3G牌照正式发放 三运营商分获三张牌照
传今年Windows Live Hotmail将启动POP3访问
iTunes音乐商店全面放弃DRM版权保护
令人失望 本届Macworld Keynote内容总结
百度阿拉丁计划 - 看上去很美