注册并发随机密码到指定邮件

<!--#include file="Include/Md5.asp"-->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%
     dim conn  
     dim connstr
     on error resume next
     connstr="DBQ="+server.mappath("Database/ameav_Site.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"   '数据库连接
     set conn=server.createobject("ADODB.CONNECTION")
     conn.open connstr
%>

<%
function IsValidMemName(memname)
  dim i, c
  IsValidMemName = true
  if not (3<=len(memname) and len(memname)<=16) then
    IsValidMemName = false
    exit function
  end if  
  for i = 1 to Len(memname)
    c = Mid(memname, i, 1)
    if InStr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-", c) <= 0 and not IsNumeric(c) then
      IsValidMemName = false
      exit function
    end if
  next
end function

function IsValidEmail(email)
  dim names, name, i, c
  IsValidEmail = true
  names = Split(email, "@")
  if UBound(names) <> 1 then
    IsValidEmail = false
    exit function
  end if
  for each name in names
    if Len(name) <= 0 then
      IsValidEmail = false
      exit function
    end if
    for i = 1 to Len(name)
      c = Mid(name, i, 1)
      if InStr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.", c) <= 0 and not IsNumeric(c) then
        IsValidEmail = false
        exit function
      end if
    next
    if Left(name, 1) = "." or Right(name, 1) = "." then
      IsValidEmail = false
      exit function
    end if
  next
  if InStr(names(1), ".") <= 0 then
    IsValidEmail = false
    exit function
  end if
  i = Len(names(1)) - InStrRev(names(1), ".")
  if i <> 2 and i <> 3 then
    IsValidEmail = false
    exit function
  end if
  if InStr(email, "..") > 0 then
    IsValidEmail = false
  end if
end function
%>
<%if request("action")="send" then%>
<%

  '参数说明
  'Subject     : 邮件标题
  'MailAddress : 发件服务器的地址,如smtp.163.com
  'Email       : 收件人邮件地址
  'Sender      : 发件人姓名
  'Content     : 邮件内容
  'Fromer      : 发件人的邮件地址

Sub SendAction(subject, email, sender, content)
Set JMail = Server.CreateObject("JMail.Message")
JMail.Charset = "gb2312" ' 邮件字符集,默认为"US-ASCII"
JMail.From = strMailUser ' 发送者地址
JMail.FromName = sender' 发送者姓名
JMail.Subject =subject
JMail.MailServerUserName = strMailUser' 身份验证的用户名
JMail.MailServerPassword = strMailPass ' 身份验证的密码
JMail.Priority = 3
JMail.AddRecipient(email)
JMail.Body = content
JMail.Send(strMailAddress)
End Sub
  
  '调用此Sub的例子
    Dim strSubject,strEmail,strMailAdress,strSender,strContent,strFromer,strHomePage,strpsw
    strSubject            =    "欢迎您注册常德二中校干竞选网络投票系统!"
    strContent            =    "欢迎您注册常德二中校干竞选网络投票系统!以下是您的注册信息:"& VbCrLf & "用户名:" & Request("MemName") & VbCrLf & "密码:" & Request("Password")& VbCrLf & "网址:" & Request("HomePage")
    strSender            =    Request("MemName")
    strHomePage            =    Request("HomePage")
    strpsw                =   Request("Password")
    strEmail            =    Request("Email") '这是收信的地址,可以改为其它的邮箱
    strMailAddress        =    "smtp.qq.com" '‘发件服务器地址   例:smtp.163.com(为163服务器地址)
    strMailUser            =    "cdsez@cdsez.com" '我司企业邮局用户名
    strMailPass            =    "*****" '邮局用户密码

if not IsValidMemName(strSender) then
'    Response.Write "<script>alert('用户名错误!');history.back();</SCRIPT>"
    Response.Write "<script>alert('Wrong Member Name!');history.back();</SCRIPT>"
    response.end
end if

  set rsRepeat = conn.execute("select MemName from ameav_Members where MemName='" & strSender & "'")
  if not (rsRepeat.bof and rsRepeat.eof) then
'    Response.Write "<script>alert('用户名重复!');history.back();</SCRIPT>"
    Response.Write "<script>alert('Member Name Repeat!');history.back();</SCRIPT>"
    response.end
end if

if not IsValidEmail(strEmail) then
'    Response.Write "<script>alert('电子邮件错误');history.back();</SCRIPT>"
    Response.Write "<script>alert('Wrong Email!');history.back();</SCRIPT>"
    response.end
end if

  set rsRepeat = conn.execute("select Email from ameav_Members where Email='" & strEmail & "'")
  if not (rsRepeat.bof and rsRepeat.eof) then
'    Response.Write "<script>alert('电子邮件重复');history.back();</SCRIPT>"
    Response.Write "<script>alert('Email Repeat!');history.back();</SCRIPT>"
    response.end
end if

set rs = server.createobject("adodb.recordset")
sql="select * from ameav_Members"
rs.open sql,conn,1,3
rs.addnew
    rs("MemName")    =   strSender
    rs("Email")        =    strEmail
    rs("Password")    =    Md5(strpsw)
    rs("AddTime")    =    now()
rs.update
rs.close
set rs=nothing
Response.Write "<script>alert('OK,Password has sent to your Email!');location.href= 'html/main.asp';</SCRIPT>"
    Call SendAction (strSubject,strEmail,strSender,strContent)
'Response.Write "<script>alert('OK!');location.href= 'html/main.asp';</SCRIPT>"
%>
<%else%>
<%
Randomize()
n=Int((999999-100000+1)*Rnd(now())+1)
%>
<style type="text/css">
<!--
body { margin-top: 50px;margin-bottom: 0px;}
td {font-size: 14px; text-decoration: none;}
-->
</style>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#666666">
<tr><td height="40" bgcolor="#E3E3E3" align="center"><b><font color=red size=3>用户注册 进入<a href="http://vote.gqt.cdsez.cn" target=_blank>投票系统</a></font></b></td></tr>
<tr><td height="10" bgcolor="#E3E3E3" align="center"><hr size="1" noshade="noshade" style="border:1px #ff0000 dotted"/></td></tr>
<tr><td height="50" bgcolor="#E3E3E3" align="center"> 为防止恶意注册,本站将随机密码发送到您邮箱,请务必填写您的真实邮箱!</td></tr>
<tr><td>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<form name="form" method="post" action="?action=send">
<tr bgcolor="#FFFFFF"><td align="center" height=50>用户名:<input name="MemName" type="text" id="MemName" size="20"> <font color="#CC0000">* 必填</font></td>
</tr>
<tr bgcolor="#FFFFFF"><td align="center" height=50>邮 箱:<input name="Email" type="text" id="Email" size="20"> <font color="#CC0000">* 必填</font></td></tr>
<tr bgcolor="#FFFFFF"><td align="center" ><input name="Password"  type="text" id="Password" value="<%=n%>">
<input type=hidden id=HomePage name=HomePage value="http://vote.gqt.cdsez.cn"><input type="submit" name="Submit" value=" 提 交 "></td></tr>
</form>
</table>
</td>
</tr>
<tr><td height="100" bgcolor="#E3E3E3" align="center"><a href="http://gqt.cdsez.cn" target=_blank>共青团常德市二中委员会</a>  进入<a href="http://vote.gqt.cdsez.cn" target=_blank>常德市二中校级学生干部竞选网络投票系统</a><br></br>黄辉 设计制作 2010.9.30</td></tr>
</table>
<%end if%>

评论: 0 | 引用: 0 | 查看次数: 550
发表评论
你没有权限发表留言!
广告