asp.net_asp 用户登录代码

更新时间:2016-10-08    来源:js教程    手机版     字体:

【www.bbyears.com--js教程】

文章提供一款简单的asp 用户登录代码,提供了从数据库教程连接到文件的登录以及用户在输入信息时js判断验证哈。
<%
"dim databasename,conn,constr
databasename="userman.mdb"
constr="provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(databasename)
set conn=server.createobject("adodb.connection")
conn.open constr
%>

登录页面文件


请输入用户名和密码

<script language = "vbscript">
function chkfields()
 name = document.myform.username.value
   if document.myform.username.value ="" then
     window.alert("请输入用户名!")
     return false
   end if
   if document.myform.userpwd.value ="" then
     window.alert("请输入密码!")
     return false
   end if
   if document.myform.email.value = "" then
     window.alert("请输入电子邮件!")
  return false
   end if
   return true
end function
</script>

用户注册







 
    用 户 名:
     *用户名只能输入大写或小写字母
 
 
    密  码:
    word" name = "userpwd" size = 20> *密码只能输入数字
 
  
    电子邮件
     *请填写正确的邮件格式
 

 

  





登录处理文件
<%
"读取从表单传递过来的身份数据
username=trim(request.form("username"))
userpwd=request.form("userpwd")
email=request.form("email")

if username="" or userpwd="" or email="" then
 response.write "<script>alert("填写不完全!");history.back();</script>"
 response.end
elseif not checkletter(username) then
 response.write "<script>alert("输入的用户名没有全部是大写或小写字母!");history.back();</script>"
 response.end
elseif not isnumeric(userpwd) then
 response.write "<script>alert("输入的密码为非数字!");history.back();</script>"
 response.end
elseif not isvalidemail(email) then
 response.write "<script>alert("输入的邮件地址格式不正确!");history.back();</script>"
 response.end
elseif len(username)<6 then
 response.write "<script>alert("用户名长度至少6位!");history.back();</script>"
 response.end
else
 response.write "

输入正确!"
end if

function checkletter(str)
 checkletter=true
 letters="abcdefghijklmnopqrstuvwxyz"
 for i=1 to len(str)
  checkchar=ucase(mid(str,i,1))   返回字符串str中第i个字符,并将其转换为大写
  if (instr(letters,checkchar)<=0) then   "checkchar对应字符在letters中不存在
   checkletter=false
   exit function
  end if
 next
end function

function isvalidemail(email)
 dim names,name,i,c
 isvalidemail=true
 names=split(email,"@")   "使用@字符将email字符串分成几个子字符串并保存在names数组中
 if ubound(names)<>1 then
  "ubound函数返回数组names的最大下标,ubound(names)<>1表明email字符串中存在@字符且不只一个,所以email不是有效的邮件地址格式
  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))
   "返回字符串name内第i个字符并将其转换成小写
   if instr("abcdefghijklmnopqrstuvwxyz_-.",c)<=0 and not isnumeric(c) then
    "instr函数返回指定字符串在另一字符串中第一次出现的位置。instr("abcdefghijklmnopqrstuvwxyz_-.",c)<=0表明字符c不在字符串"abcdefghijklmnopqrstuvwxyz_-."中
    isvalidemail=false
    exit function
   end if
  next
  if left(name,1)="." or right(name,1)="." then
   "返回字符串name最左边一个字符,返回字符串name最右边一个字符
   isvalidemail=false
   exit function
  end if
 next
 if instr(names(1),".")<=0 then
  "email字符串中@右边部分不包含字符”.”
  isvalidemail=false
  exit function
 end if
 i=len(names(1))-instrrev(names(1),".")
 "instrrev函数返回指定字符串在另一个字符串中出现的从结尾计起的的位置,instrrev(names(1),".")得到字符"."在字符串names(1) 中从结尾计起的位置
 if i<>2 and i<>3 then
  "电子邮件最后一般为cn或com,长度为2或3
  isvalidemail=false
  exit function
 end if
 "email中存在字符串".."
 if instr(email,"..")>0 then
  isvalidemail=false
 end if
end function
%>

本文来源:http://www.bbyears.com/wangyezhizuo/27399.html

猜你感兴趣

热门标签

更多>>

本类排行