ASP+MS SQL線上修改Serv-u的密碼教程

來源:互聯網
上載者:User
asp+|serv-u|sql|教程|線上

下面是以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]([Name] )

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]([Name] )

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]([Name] )


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]([Name] )

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]([Name] )

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]([Name] )

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

提示:代碼僅實現更改密碼的功能,並不一定完全符合或達到您的需求。

<!--#include file='conn.asp'-->
<!--#include file='include/md5.asp'-->
<%
dim act,UserName,OldPassword,NewPassword,reNewPassword
act = Request.form("act")
if act = "update" then

 UserName  = Request.form("UserName")
 OldPassword  = Request.form("OldPassword")
 NewPassword  = Request.form("NewPassword")
 reNewPassword = Request.form("reNewPassword")
 UserName  = Replace(UserName,"'","'")

 if len(UserName)<1 or len(OldPassword)<1 or len(NewPassword)<1 or len(reNewPassword)<1 then
  alert("表單沒有填寫完整")
 end if

 if trim(NewPassword)<>trim(reNewPassword) then
  alert("密碼與確認密碼不一樣")
 end if

 Sql0 = "select top 1 name,[password] from [useraccounts] where name = '"& UserName &"'"
 set rs0 = conn.execute(Sql0)
 if rs0.eof and rs0.bof then
  alert("使用者名稱不存在")
 else
  dbname = rs0("name")
  dbpassword = rs0("password")
 end if

 cdbpassword = left(dbpassword,2) & md5(left(dbpassword,2) & OldPassword)

 if trim(cdbpassword) <> trim(dbpassword) then
  alert("密碼錯誤")
 else
  rndstr = MyRandc(2) '兩位隨機字母
  newdbpassword = rndstr &  md5(rndstr & NewPassword)
  sql2 = "update [useraccounts] set [password] = '"& newdbpassword &"' where name='"& UserName &"'"
  conn.execute(sql2)
  alert("密碼已經更改,可能要幾鐘後才會生效")
 end if
end if

function alert(x)
 response.write "<script language='JavaScript'>alert('"& replace(x,"""","\""") &"');history.go(-1);</script>"
 conn.close
 set conn = nothing
 response.end
end function

function MyRandc(n)'產生隨機字元,n為字元的個數
 thechr = ""
 for i=1 to n
  Randomize timer
  zNum = cint(25*Rnd)
  if zNum mod 2 = 0 then
   zNum = zNum + 97
  else
   zNum = zNum + 65
  end if
  thechr = thechr & chr(zNum)
 next
 MyRandc = thechr
end function
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<META NAME="Author" CONTENT="網頁教學網">
<META NAME="Keywords" CONTENT="http://www.webjx.com">
<title>更改FTP (Serv-U) 密碼 - 51windows.net</title>
</head>
<body>
<form method="POST" action="" name="form" autocomplete="off">
<input type="hidden" name="act" value="update">
<div align="center">
  <center>
      <table border="0" width="480" cellpadding="2" cellspacing="1" class="table" style="border: 1 solid #336699;font-size:14px;">
        <tr>
          <td width="100%" align="center" colspan="2" class="title" style="background:#336699;color:#FFFFFF;">更改FTP (Serv-U) 密碼</td>
        </tr>

        <tr>
          <td width="30%" align="left"> 使用者名稱[√]:</td>
          <td width="70%"><input class="input" type="text" maxlength=20  name="UserName" size="25" value="" /> (FTP登陸使用者名稱)</td>
        </tr>
 
        <tr>
          <td width="30%" align="left"> 舊密碼[√]:</td>
          <td width="70%"><input class="input" type="password" maxlength=20  name="OldPassword" size="25" value="" /> (必須輸入舊密碼)</td>
        </tr>

        <tr>
          <td width="30%" align="left"> 新密碼[√]:</td>
          <td width="70%"><input class="input" type="password" name="NewPassword" size="25" value="" /> (輸入新密碼)</td>
        </tr>

        <tr>
          <td width="30%" align="left"> 確 認[√]:</td>
          <td width="70%"><input class="input" type="password" name="reNewPassword" size="25" value="" /> (再次輸入新密碼)</td>
        </tr>

        <tr>
          <td width="100%" height="30" align="center" colspan="2"><input style="font-size:14px;" type="submit" size="10" value="確 定" class=button></td>
        </tr>
      </table>
  </center>
</div>
</html>
<%
set rs = nothing
conn.close
set conn = nothing
%>



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.