<!--#include file="conn/hl_conn.asp" -->
<%
Dim CheckNameExist,checkbadname,StrName,StrLen,regcheck
Dim t_StrValue,StrInfo
t_StrValue = Replace(Request("value"),"'","")

set regexpobj=new regexp 
regexpobj.pattern="^[\u4e00-\u9fa5]+$" 
regcheck=regexpobj.test(t_StrValue) 
set regexpobj=nothing
 
if Request("act")="Email" Then
	If t_StrValue="" Then
		StrInfo = "empty"
	ElseIf IsValidEmail(t_StrValue) Then 
		If CheckEmailExist(t_StrValue) Then 
			StrInfo = "OK"
		Else
			StrInfo = "exist"
		End If 
	Else
		StrInfo = "bad"
	End If 
	Response.write StrInfo
ElseIf Request("act")="name" Then'a---
	  If t_StrValue="" Then'--b
		   StrInfo = "empty"		         
	  Else
	     If regcheck Then'-----c
	       StrLen=Len(t_StrValue)+1
	     Else 
	       StrLen=Len(t_StrValue)
	     End If'---------c------end
	 
	     If  StrLen<20 And StrLen>2 Then'-----d 
	  	    Set RS=Server.CreateObject("Adodb.recordset")
	        CheckSql="Select username from hl_user where username='"&t_StrValue&"'"
			 RS.open CheckSql,conn,1,1
		      IF Not RS.eof Then
		         CheckNameExist="False"
				 StrInfo="exist"				 
			  Else
		         CheckNameExist="True"				
		      End If
			RS.Close
		    Set RS=nothing
			 
			IF CheckNameExist="True" then'-------e
	             Dim StrBadName,StrArrBN,j
	                StrBadName="管理员|操你妈|游客|法轮|guest|admin|administrator|李洪志|江泽民|胡锦涛|*|TAB|\r|\n|<|>|&"
	              If InStr(StrBadName,"|")>0 Then 
		              StrArrBN = Split(StrBadName,"|")
	              Else
		              StrArrBN = Array(StrBadName)
	              End If 
				     
	              For j=LBound(StrArrBN) To UBound(StrArrBN)
				     
		              If StrArrBN(j)=t_StrValue Then 
		                 checkbadname ="True"
					  exit for
					  Else
			             checkbadname ="False"
	                  End If
				  Next 	                
	              IF checkbadname = "False" Then
		               StrInfo="OK"
		          Else
		               StrInfo ="bad"
			      End iF
			End IF'------------e-end
		Else
	       StrInfo = "bad"
		End if
	  End If'----------b--end

	Response.write StrInfo
End If '----a--end

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 = LCase(Mid(name, i, 1))
        If InStr("abcdefghijklmnopqrstuvwxyz_-.", 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 And i <> 4 Then
       IsValidEmail = False
       Exit Function
    End If
    If InStr(email, "..") > 0 Then
       IsValidEmail = False
    End If
End Function

Function CheckSQLInj(StrName)
CheckSQLInj=False
If Instr(StrName,"=")>0 or Instr(StrName,"%")>0 or Instr(StrName,chr(32))>0 or Instr(StrName,"?")>0 or Instr(StrName,"&")>0 or Instr(StrName,";")>0 or Instr(StrName,",")>0 or Instr(StrName,"'")>0 or Instr(StrName,",")>0 or Instr(StrName,chr(34))>0 or Instr(StrName,chr(9))>0 or Instr(StrName,"")>0 or Instr(StrName,"$")>0 Then
CheckSQLInj=False
Response.End()
Else
CheckSQLInj=True
End If
End Function
%>