ASP+MS SQL在线修改Serv-u的密码教程

下面是以Serv-U 6.0和Sql Server 2000相结合的演示。

建表Sql 语句:

CREATE TABLE [groupaccounts] (
[id] int IDENTITY (1,1) PRIMARY KEY,
[Index] int Default 0,
[Name] nVarChar(50) default '',
[Notes] nVarChar(255) default ''
)
CREATE INDEX [Name] on groupaccounts

CREATE TABLE [groupdiraccess] (
[id] int IDENTITY PRIMARY KEY,
[Access] nVarChar(255) default '',
[Index] int Default 0,
[Name] nVarChar(50) default ''
)
CREATE INDEX [Name] on groupdiraccess

CREATE TABLE [groupipaccess] (
[id] int IDENTITY PRIMARY KEY,
[Access] nVarChar(255) default '',
[Index] int Default 0,
[Name] nVarChar(50) default ''
)
CREATE INDEX [Name] on groupipaccess

CREATE TABLE [useraccounts] (
[id] int IDENTITY PRIMARY KEY,
[Access] nVarChar(255) default '',
[AlwaysLogin] int Default 0,
[ChangePass] int Default 0,
[Disable] int Default 0,
[Expirationtype] int Default 0,
[Expiration] datetime Default '1980-1-1',
[Groups] nVarChar(50) default '',
[HideHidden] int Default 0,
[HomeDir] nVarChar(100) default '',
[idleTimeOut] int Default 0,
[LogMesfile] nVarChar(100) default '',
[MaxIp] int Default -1,
[MaxSpeedDown] decimal Default 0,
[MaxSpeedUp] decimal Default 0,
[MaxUsers] int Default -1,
[Name] nVarChar(50) default '',
[Needsecure] int Default 0,
[Notes] nVarChar(255) default '',
[PassType] int Default 0,
[Password] nVarChar(50) default '',
[Privilege] int Default 0,
[QuotaCurrent] decimal Default 0,
[QuotaEnable] int Default 0,
[QuotaMax] decimal Default 0,
[RatioCredit] decimal Default 0,
[RatioDown] int Default 0,
[RatioType] int Default 0,
[RatioUP] int Default 0,
[RelPaths] int Default 0,
[SessionTimeOut] int Default 0,
[SkeyValues] nVarChar(50) default ''
)
CREATE INDEX [Name] on useraccounts

CREATE TABLE [userdiraccess] (
[id] int IDENTITY PRIMARY KEY,
[Access] nVarChar(255) default '',
[Index] int Default 0,
[Name] nVarChar(50) default ''
)
CREATE INDEX [Name] on userdiraccess

CREATE TABLE [useripaccess] (
[id] int IDENTITY PRIMARY KEY,
[Access] nVarChar(255) default '',
[Index] int Default 0,
[Name] nVarChar(50) default ''
)
CREATE INDEX [Name] on useripaccess

ServUDaemon.ini 中的ODBC信息:
ODBCSource=Serv-U||
ODBCTables=useraccounts|groupaccounts|userdiraccess|groupdiraccess|useripaccess|groupipaccess
ODBCColumns=Name|Password|SkeyValues|HomeDir|LogMesfile|Access|Disable|Needsecure|RelPaths|HideHidden|AlwaysLogin|ChangePass|QuotaEnable|MaxIp|MaxSpeedUp|MaxSpeedDown|MaxUsers|idleTimeOut|SessionTimeOut|RatioUP|RatioDown|RatioCredit|QuotaCurrent|QuotaMax|Expiration|Privilege|PassType|RatioType|Groups|Notes|Index

我们利用Serv-U的obdc功能,可以把FTP用户信息存在数据库中,这样对Web操作方便了很多,下面是在线更改密码的列子,数据库为Access,表和字段的设计请参考Serv-U的帮助文件。

加密算法为随机码与MD5 32 位加密,例如:
两个随机字母:ab
用户输入密码:123456
生成的密码为:ab + MD5(ab123456)

补充:md5返回为32位的大写字符,附 md5.asp

提示:代码仅实现更改密码的功能,并不一定完全符合或达到您的需求。

 1   
 2dim act,UserName,OldPassword,NewPassword,reNewPassword   
 3act = Request.form("act")   
 4if act = "update" then 
 5
 6UserName = Request.form("UserName")   
 7OldPassword = Request.form("OldPassword")   
 8NewPassword = Request.form("NewPassword")   
 9reNewPassword = Request.form("reNewPassword")   
10UserName = Replace(UserName,"'","'") 
11
12if len(UserName)<1 or len(OldPassword)<1 or len(NewPassword)<1 or len(reNewPassword)<1 then   
13alert("表单没有填写完整")   
14end if 
15
16if trim(NewPassword)<>trim(reNewPassword) then   
17alert("密码与确认密码不一样")   
18end if 
19
20Sql0 = "select top 1 name,[password] from [useraccounts] where name = '"& UserName &"'"   
21set rs0 = conn.execute(Sql0)   
22if rs0.eof and rs0.bof then   
23alert("用户名不存在")   
24else   
25dbname = rs0("name")   
26dbpassword = rs0("password")   
27end if 
28
29cdbpassword = left(dbpassword,2) & md5(left(dbpassword,2) & OldPassword) 
30
31if trim(cdbpassword) <> trim(dbpassword) then   
32alert("密码错误")   
33else   
34rndstr = MyRandc(2) '两位随机字母   
35newdbpassword = rndstr & md5(rndstr & NewPassword)   
36sql2 = "update [useraccounts] set [password] = '"& newdbpassword &"' where name='"& UserName &"'"   
37conn.execute(sql2)   
38alert("密码已经更改,可能要几钟后才能生效")   
39end if   
40end if 
41
42function alert(x)   
43response.write "

<script language="JavaScript">alert('"& replace(x,"""","""") &"');history.go(-1);</script>

 1"   
 2conn.close   
 3set conn = nothing   
 4response.end   
 5end function 
 6
 7function MyRandc(n)'生成随机字符,n为字符的个数   
 8thechr = ""   
 9for i=1 to n   
10Randomize timer   
11zNum = cint(25*Rnd)   
12if zNum mod 2 = 0 then   
13zNum = zNum + 97   
14else   
15zNum = zNum + 65   
16end if   
17thechr = thechr & chr(zNum)   
18next   
19MyRandc = thechr   
20end function   
 1<html>
 2<head>
 3<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
 4<meta content="海娃(51windows)" name="Author"/>
 5<meta content=" http://www.51windows.Net " name="Keywords"/>
 6<title>更改FTP (Serv-U) 密码 - 51windows.net</title>
 7</head>
 8<body>
 9<form action="" autocomplete="off" method="POST" name="form">
10<input name="act" type="hidden" value="update"/>
11<div align="center">
12<center>
13<table border="0" cellpadding="2" cellspacing="1" class="table" style="border: 1 solid #336699;font-size:14px;" width="480">
14<tr>
15<td align="center" class="title" colspan="2" style="background:#336699;color:#FFFFFF;" width="100%">更改FTP (Serv-U) 密码</td>
16</tr>
17<tr>
18<td align="left" width="30%"> 用户名[√]:</td>
19<td width="70%"><input class="input" maxlength="20" name="UserName" size="25" type="text" value=""> (FTP登陆用户名)</input></td>
20</tr>
21<tr>
22<td align="left" width="30%"> 旧密码[√]:</td>
23<td width="70%"><input class="input" maxlength="20" name="OldPassword" size="25" type="password" value=""/> (必须输入旧密码)</td>
24</tr>
25<tr>
26<td align="left" width="30%"> 新密码[√]:</td>
27<td width="70%"><input class="input" name="NewPassword" size="25" type="password" value=""/> (输入新密码)</td>
28</tr>
29<tr>
30<td align="left" width="30%"> 确 认[√]:</td>
31<td width="70%"><input class="input" name="reNewPassword" size="25" type="password" value=""/> (再次输入新密码)</td>
32</tr>
33<tr>
34<td align="center" colspan="2" height="30" width="100%"><input class="button" size="10" style="font-size:14px;" type="submit" value="确 定"/></td>
35</tr>
36</table>
37</center>
38</div>
39</form></body></html>
1   
2set rs = nothing   
3conn.close   
4set conn = nothing   
Published At
Categories with Web编程
Tagged with
comments powered by Disqus