ASP Complete Login Code

Source: Internet
Author: User

ASP Full Login code
<%
Option Explicit
' forces the browser to re-enter the server download page instead of reading the page from the cache
Response.Buffer = True
Response.Expires =-1
Response.ExpiresAbsolute = Now ()-1
Response.Expires = 0
Response.CacheControl = "no- Cache "
' is primarily to make random picture numbers randomly appear
%>
<!--#include file=" inc/config.asp "
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en"


<TITLE>< %=rs_config ("C_incname")%>-administrator login </title>
<meta http-equiv= "Content-type" content=; charset=gb2312 ""
<link href= "Inc/login.css" Rel=stylesheet type=text/css>
<base target= "main"
<style type= "Text/css"
<!--
. style2 {font-size:12pt}

</style>
< SCRIPT Language=javascript>
<!--
Function Frmsubmit () {

if (TheForm.name.value = = "") {
Alert ("Please enter user name");
TheForm.name.focus ();
return false;
}
if (TheForm.pass.value = = "") {
Alert ("Please enter a password");
TheForm.pass.focus ();
return false;
}
if (TheForm.safecode.value = = "") {
Alert ("Please input check code");
TheForm.safecode.focus ();
return false;
}

return true;
}
-->
</SCRIPT>
<link rel= "icon" href= "/favicon.ico" type= "Image/x-icon"/>
<link rel= "shortcut icon" href= "/favicon.ico" type= "Image/x-icon"/>
<meta http-equiv=content-type content= "text/html; charset=gb2312 ">
<link
href= "Images/wei.css" Type=text/css rel=stylesheet>
<meta content= "Microsoft FrontPage 4.0" name=generator>
</HEAD>
<body bgcolor= #ffffff >
<BR>
<br>
<br>
<br>
<br>
<BR>
<table align= "center" cellspacing=0 cellpadding=0 width=555 border=0 style= "Border-collapse:collapse" bordercolor= "#111111" >
<TBODY>
<TR>
&LT;TD width= "588" >
<table align= "center" cellspacing=0 cellpadding=0 width=558 border=0 style= "Border-collapse:collapse" bordercolor= "#111111" >
<TBODY>
<TR>
&LT;TD valign=top width= "360" height= ">"
<form action=logincheck.asp method=post target= "_top" >
<table width= "border=" 0 "align=" center "cellpadding=" 0 "cellspacing=" 0 ">
<tr>
&LT;TD colspan= "2" ></td>
</tr>
<tr>
&LT;TD width= "508" valign= "Top" background= "Images/admin_login2.gif" ><table width= "508" border= "0" cellspacing = "0" cellpadding= "0" >
<tr>
&LT;TD height= "Panax Notoginseng" colspan= "6" >&nbsp;</td>
</tr>
<tr>
&LT;TD width= "A" rowspan= "2" >&nbsp;</td>
&LT;TD width= "126" ><font color= "#043BC9" > User name:</font></td>
&LT;TD width= "rowspan=" 2 ">&nbsp;</td>
&LT;TD width= "131" ><font color= "#043BC9" > User password:</font></td>
&LT;TD width= ">&nbsp;</td>"
&LT;TD width= "><font" color= "#043BC9" > Captcha: <b><font color= #ff0000 >Src= "inc/code.asp" width= "height=" align= "Absmiddle" ></font></b></font></td>
</tr>
<tr>
<td><input name=name id= "name" size=15></td>
<td><input name=pass type=password id= "Pass" size=12></td>
<td>&nbsp;</td>
<td><input name= "Safecode" Type=text id= "Safecode" size=12></td>
</tr>
</table></td>
<td>
<input type= "image" Name= "Submit" src= "Images/admin_login3.gif" style= "width:92px"; height:126px; " ></td>
</tr>
</table>
</FORM>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
</BODY>
</HTML>

Here is the ASP processing file
<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">

<!--#include file= "conn.asp"-->
<!--#include file= "md5.asp"-->

<%
function Chkpost ()
Dim server_v1,server_v2
Chkpost=false
Server_v1=cstr (Request.ServerVariables ("Http_referer"))
Server_v2=cstr (Request.ServerVariables ("SERVER_NAME"))
If Mid (Server_v1,8,len (SERVER_V2)) <>server_v2 Then
Chkpost=false
Else
Chkpost=true
End If
End Function
Session. Timeout=20
If Chkpost=false Then
' emsg= ' Please do not submit a table from another site.
Response. Redirect ("login.asp?emsg= please do not submit table from other site")
Response.End ()
End If

Dim aname,apass,founderr,errmsg
Founderr=false
Aname=replace (Trim (Request ("name"), "'", "")
Apass=replace (Trim (Request ("Pass"), "'", "")
Safecode=replace (Trim (Request ("Safecode")), "'", "" "
If Len (aname) >20 or Len (aname) <3 Then
Founderr=true
errmsg=errmsg& "User name is not right!" \ n '
End If

If Len (apass) >20 or Len (apass) <6  then
   founderr=true
   errmsg=errmsg & "User password is wrong!" \ n \ nthe "
End If
if safecode=" "Then
 founderr=true
 errmsg=errmsg &" Verify code cannot be empty! \ n "
End If
if session (" Admin_getcode ") =" "Then
 founderr=true
 errmsg=errmsg &" You are logged in too long , please return to the login page to sign in again. \ n "
End If
if SAFECODE<>CSTR (session (" Admin_getcode ")) then
 founderr=true
 errmsg= ErrMsg & "The confirmation code you entered is inconsistent with the system, please re-enter it." \ n "
End If
if Founderr=true then
   call Loginerror (errmsg)
   conn.close
  ;  Set conn=nothing
Else

Apass=md5 (Apass)
Dim sql,rs
Sql= "Select A_name,a_pass,a_flag from admin where A_name= '" &aname& "' and a_pass= ' &apass& ' '
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open sql,conn,1,1
If Rs. BOF and Rs. EOF then
    errmsg= username or password error!
 call loginerror (errmsg)
Rs.close
Set rs=nothing
conn.close
Set conn=nothing
Response. End
ElseIf not (Rs. BOF or Rs. EOF) then
session ("Aname") =rs ("A_name")
session ("Admin_flag") = ' into '
session ("Admin_sys") =rs ("A_flag")
Response. Redirect ("useradmin.asp")
Rs.close
Set rs=nothing
conn.close
Set conn=nothing
Response. End
End If
End if

Sub Loginerror (emsg)
Response.Write "<script language= ' JavaScript ' >" & Chr (13)
Response.Write "Alert (' &EMsg&"); "& Chr (13)
Response.Write "window.document.location.href= ' login.asp ';" &CHR (13)
Response.Write "</script>" & Chr (13)
Response.End
End Sub

%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.