Important alert: (current site time 7/15/2013 10:13:18 PM EDT)
 

VB icon

asp password protection

Email
Submitted on: 2/28/2001 12:41:05 AM
By: Faisal Arif  
Level: Intermediate
User Rating: By 5 Users
Compatibility: ASP (Active Server Pages)
Views: 67549
author picture
(About the author)
 
     Asp Password Protection for website
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: asp password protection
' Description:Asp Password Protection for website
' By: FaisalArif
'
' Inputs:name the files accordingly as mentioned in the source code
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=6515&lngWId=4'for details.'**************************************

password.asp
<%@ LANGUAGE="VBSCRIPT" %>
<!--- This example is a simple login system --->
<HTML>
<HEAD>
 <TITLE>Password.asp</TITLE>
</HEAD>
<BODY>
 <FORM ACTION="engine.asp" NAME="form1" METHOD="post">
 User Name: <INPUT TYPE="text" SIZE=30 NAME="username">
 <P>
 Password: <INPUT TYPE="password" SIZE=30 NAME="password">
 <P>
 <INPUT TYPE="submit" VALUE="Login">
 </FORM>
</BODY>
</HTML>
--------------------------------------------------------------------------------
engine.asp
-------------
<%@ LANGUAGE="VBSCRIPT" %>
<%
 ' Connects and opens the text file
 ' DATA FORMAT IN TEXT FILE= "username<SPACE>password"
 Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
 Set MyTextFile=MyFileObject.OpenTextFile(Server.MapPath("\path\path\path\path") & "\passwords.txt") 
 ' Scan the text file to determine if the user is legal
 WHILE NOT MyTextFile.AtEndOfStream
' If username and password found
IF MyTextFile.ReadLine = Request.form("username") & " " & Request.form("password") THEN
' Close the text file
MyTextFile.Close
' Go to login success page
Session("GoBack")=Request.ServerVariables("SCRIPT_NAME")
Response.Redirect "inyougo.asp"
Response.end
END IF
 WEND
 ' Close the text file
 MyTextFile.Close
 ' Go to error page if login unsuccessful
 Session("GoBack")=Request.ServerVariables("SCRIPT_NAME")
 Response.Redirect "invalid.asp"
 Response.end
%> 
------------
invalid.asp
-----
<%@ LANGUAGE="VBSCRIPT" %>
<!--- This example is a simple login system ---> 
<HTML>
<HEAD>
<TITLE>invalid.asp</TITLE>
</HEAD>
<BODY>
You have entered an invalid username or password.
<P>
<A HREF="password.asp">Try to log in again</A>
</BODY>
</HTML>
------
inyougo.asp
------
<%@ LANGUAGE="VBSCRIPT" %> 
<!--- This example is a simple login system ---> 
<HTML>
<HEAD>
 <TITLE>In You Go</TITLE>
</HEAD>
<BODY>
 You have now entered the password protected page.
</BODY>
</HTML> 
-------
passwords.txt
----
gates bill
burns joe 


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

3/1/2001 4:59:34 AMDaniel

Its a good example of how you use a text file and store information in it, but i stronlgy suggest that you wont use this method as a pass verifier since it has VEERRRYY low security!!
(If this comment was disrespectful, please report it.)

 
3/8/2001 12:10:50 AMBennet

Very good for beginners
(If this comment was disrespectful, please report it.)

 
8/2/2001 4:07:51 AMAcidReign

I'm sorry but this is a poor example, you are setting session variables, and not using them, you are using an unnecessary loop, you have several HTML only file, yet you use .asp, this is also unnecessary server load.
instead of a loop, try arrUsers = Split( Replace( MyTextFile.ReadAll, Chr(13),
(If this comment was disrespectful, please report it.)

 
8/2/2001 4:09:28 AMSean Jamieson

, Chr(10) )
remeber: never use a loop unless it is absolutely necessary.
(If this comment was disrespectful, please report it.)

 
8/8/2002 5:29:45 AMPratheep Y Roy

Good One Really Nice
(If this comment was disrespectful, please report it.)

 
12/16/2003 2:18:50 AM

actuall it is a low security
because your r using the text file to store the username and password
it is very easy to break from txt file
and also your are using unnecessary loop.if the users increases then automatically the process becomes slow down


(If this comment was disrespectful, please report it.)

 
12/18/2003 4:43:19 AM

Excuse me, but how can don't use a loop.
I have a similar script that control username and password from a database. But me to, i use a loop.
Someone can write me a system to not use a loop?
Thank you
"Best Regards"

www.armand.it
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.