<!--#include file="../inc/Bll.asp"-->
<!--#include file="../inc/Constant.asp"-->
<!--#include file="../inc/Md5.asp"-->
<!--#include file="../inc/App.asp"-->
<%
'注册验证
LocalValid
'发送邮件
LocalMail

dim t_UserID,t_UserName,t_UserPass,t_ReUserPass,t_UserNickName,t_UserMail,t_UserSex,newPass
'本地注册验证
Sub LocalValid()
	'验证数据
	if request.form("Method")<>"GetPass" then Rws "alert('非法请求!');history.back();":Rend
	CheckVCode '验证码
	t_UserName = CheckSub(vAccount,request.form("UserName"),"账号格式有误") '验证账号
	t_UserMail = CheckSub(vEmail,request.form("UserMail"),"邮箱格式有误") '验证邮箱
	if CheckRepeatUserName(t_UserName) then rws "alert('账号不存在!');history.back();":Rend
	if CheckRepeatMail(t_UserMail) then rws "alert('邮箱地址不存在!');history.back();":Rend
	if not CheckInfo(t_UserName,t_UserMail) then rws "alert('账号与邮箱不匹配!');history.back();":Rend
End Sub

function CheckInfo(uname,umail)
	RS_End
	RS.OPEN "select top 1 * from [i_User_Info] where [i_User_Name]='"&t_UserName&"' and [i_User_Mail]='"&t_UserMail&"'" , DB_CONN , 1 , 3
	if RS.recordcount>0 then
		newPass = makepassword(8)
		Rs("i_User_Pass") = MD5(newPass)
		RS.Update()
		CheckInfo = true
	else
		CheckInfo = false
	end if
	RS_End
end function

'发送邮件
Sub LocalMail()
	dim jmail
	mailserver=SysConfig("i_Sys_Config_MailServer")    '邮局服务器地址（smtp服务器地址）
	receive=t_UserMail    '接受email地址（可以是您的任何有效信箱）
	mailFROM=SysConfig("i_Sys_Config_MailAdd")    '发邮件地址
	username=SysConfig("i_Sys_Config_MailUserName")    '发件人账号
	password=SysConfig("i_Sys_Config_MailPass")    '发邮件密码
	'rw SysConfig("i_Sys_Config_MailServer")&":"&SysConfig("i_Sys_Config_MailAdd")&":"&SysConfig("i_Sys_Config_MailUserName")&":"&SysConfig("i_Sys_Config_MailPass")
	subject=SysConfig("i_Sys_Config_SysName")&" 密码重置邮件"
	body="您的"&SysConfig("i_Sys_Config_SysName")&"账号密码已经重置为: "&newPass '修改结束

	'调用邮件发送
	'群发就是 循环
	'需要在web服务器上注册组件 w3JMail4Free.exe
	call SendMail (subject, body, mailserver, receive, mailFROM, username,password)
End Sub

Sub SendMail(subject, body, mailserver, receive, mailFROM, username,password) 
	Set jmail = Server.CreateObject("JMAIL.Message") '建立发送邮件的对象 
	jmail.silent = true '屏蔽例外错误，返回FALSE跟TRUE两值j 
	jmail.logging = true '启用邮件日志 
	jmail.Charset = "GB2312" '邮件的文字编码为国标 
	jmail.ContentType = "text/html" '邮件的格式为HTML格式 
	jmail.AddRecipient receive '邮件收件人的地址 
	jmail.From = mailFROM '发件人的E-MAIL地址 
	jmail.MailServerUserName = username '登录邮件服务器所需的用户名 
	jmail.MailServerPassword = password '登录邮件服务器所需的密码 
	jmail.Subject = subject '邮件的标题 
	jmail.Priority = 1 '邮件的紧急程序，1 为最快，5 为最慢， 3 为默认值 
	jmail.Body = body
	flag=jmail.Send(mailserver) '执行邮件发送（通过邮件服务器地址）
	if flag=true then
		Rws "alert('新密码已经发送到您的注册邮箱,请注意查收!');location.href='/i/v2/login.html';"
	else
		'Rw "<font color=red>发送失败：" & Jmail.ErrorCode & "；" & Jmail.ErrorMessage & "；" & Jmail.ErrorSource & "</font>" 
		Rws "alert('邮件发送失败,请联系管理员!');history.back();"
	end if 
	jmail.Close '关闭邮件对象 
	set jmail=nothing
end sub


function makepassword(byval maxlen)

	dim strnewpass
	dim whatsnext, upper, lower, intcounter
	randomize

	for intcounter = 1 to maxlen
	whatsnext = int((1 - 0 + 2) * rnd + 0)
	if whatsnext = 0 then
	'character
	upper = 90
	lower = 65
	else
	if whatsnext=1 then
	upper=122
	lower=97
	else
	upper = 57
	lower = 48
	end if
	end if
	strnewpass = strnewpass & chr(int((upper - lower + 1) * rnd + lower))
	next
	makepassword = strnewpass
end function 
%>