首页 > 安全资讯 >

在线更改Serv-U密码示例代码

04-12-18

来源:51windows.Net 我们利用Serv-U的obdc功能,可以把FTP用户信息存在数据库中,这样对Web操作方便了很多,下面是在线更改密码的列子,数据库为Access,表和字段的设计请参考Serv-U的帮助文件。加密算法为随机码与MD5 32 位加密,例如

来源:51windows.Net


我们利用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="海娃(51windows)">
<META NAME="Keywords" CONTENT="/ target=_blank>http://www.51windows.Net">
<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
%>



md5.asp

<%
Private Const BITS_TO_A_BYTE = 8
Private Const BYTES_TO_A_WORD = 4
Private Const BITS_TO_A_WORD = 32

Private m_lOnBits(30)
Private m_l2Power(30)

Private Function LShift(lValue, iShiftBits)
  If iShiftBits = 0 Then
    LShift = lValue
    Exit Function
  ElseIf iShiftBits = 31 Then
    If lValue And 1 Then
      LShift = &H80000000
    Else
      LShift = 0
    End If
    Exit Function
  ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
    Err.Raise 6
  End If

  If (lValue And m_l2Power(31 - iShiftBits)) Then
    LShift = ((lValue And m_lOnBits(31 - (iShiftBits + 1))) * m_l2Power(iShiftBits)) Or &H80000000
  Else
    LShift = ((lValue And m_lOnBits(31 - iShiftBits)) * m_l2Power(iShiftBits))
  End If
End Function

Private Function RShift(lValue, iShiftBits)
  If iShiftBits = 0 Then
    RShift = lValue
    Exit Function
  ElseIf iShiftBits = 31 Then
    If lValue And &H80000000 Then
      RShift = 1
    Else
      RShift = 0
    End If
    Exit Function
  ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
    Err.Raise 6
  End If
  
  RShift = (lValue And &H7FFFFFFE) m_l2Power(iShiftBits)

  If (lValue And &H80000000) Then
    RShift = (RShift Or (&H40000000 m_l2Power(iShiftBits - 1)))
  End If
End Function

Private Function RotateLeft(lValue, iShiftBits)
  RotateLeft = LShift(lValue, iShiftBits) Or RShift(lValue, (32 - iShiftBits))
End Function

Private Function AddUnsigned(lX, lY)
  Dim lX4
热点推荐