Active Server Pages (ASP)
If you have Cookies enabled,
you can check to see if any files you have downloaded
have been updated since you downloaded them
by clicking here.
A collection of succinct ASP code examples,
all free, beautiful and potentially gold-dust!
My intention is to provide simple, free access to useable solutions to common but difficult programming problems.
I have treated the creation of each class as a puzzle and hopefully have evolved good solutions.
If you know any better solutions then please e-mail me so that everyone can share your wisdom!
A good place to start is the
Site Map
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
MD5
Message digest 5
This function generates a 32 byte Hash Code for a given String or File input.
Use this to generate a Unique Identifier or Checksum from a String or for a File.
To use it in an ASP file, download the following MD5.htm then save the text to MD5.asp
include MD5.asp in the ASP file you wish to use it in:
<!--#include virtual="/Shared/MD5.asp"-->
Its convenient to keep a folder in the root of your site for keeping all shared files in.
I do this and call the folder /Shared.
That way any page wishing to use a commonly used file can access it with a short path.
To get the MD5 value of a string simply call the function MD5 with the string as a parameter:
MyMD5Hash=MD5("The string to encode")
I have an example MD5 calculator which uses this.
Login Page
If you want a quick and simple way to implement secure pages using ASP you'll find the following code invaluable.
Its convenient to keep a folder in the root of your site for keeping all shared files in.
I do this and call the folder /Shared.
That way any page wishing to use a commonly used file can access it with a short path.
To implement this Login page we need a file Login.asp:
Download Login.htm and save the text to Login.asp
You'll also want to alter the titles and passwords in Login.asp
Login.asp uses MD5.asp file described above.
I keep both of these files in my /Shared folder. If you don't, then edit the code to use your paths.
Once you have those two files all you have to do is decide on user names and passwords and include some code like the following at the very top of each secured file.
This example would be the top lines of the file /MySecuredFile.asp:
<%
if (Session("UserGroup")<>"a02584819eb08c984ae94be3cd532ce4") then
Session("GoTo")="/MySecuredFile.asp"
Response.Redirect("/Shared/Login.asp")
end if
%>
If a page can be accessed by more than one user name then add them using 'and' as shown:
<%
if (Session("UserGroup")<>"e6bcda3d4d5aceabc0685091a242f3f5") _
and (Session("UserGroup")<>"ff35c102065a52d748503dfd58720bd5") then
Session("GoTo")="/MySecuredFile.asp"
Response.Redirect("/Shared/Login.asp")
end if
%>
So thats it... download two little files and add a few lines of code to the top of each page...
But we still need to create the passwords and usernames.
People are ever so naughty with passwords... They have things that are easy to remember (and therefore guess) or else they forget them.
I have a system I use for generating passwords that are unguessable, and yet memorable.
You can download it from here.
An example of a good password is imjE2A13K. It is obviously unguessable, but memorable because it rhymes, the change of case happens after the first rhyming part... But don't use this one - download the generator and get another one!
Once you have chosen your password and username you could use use the following code to convert them to MD5:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<BODY>
<!--#include virtual="/Shared/MD5.asp"-->
<%
Response.Write "Username Hash = " & MD5("MyUserName") & "<BR>" & vbCRLF
Response.Write "Password Hash = " & MD5("MyPassword") & "<BR>" & vbCRLF
%>
</BODY>
</HTML>
Save the above as tmp.asp and access it as a web page through your sever.
You will get output like:
Username Hash = 0685091a242f3f5e6bcda3d4d5aceabc
Password Hash = 48503dfd58720bd5ff35c102065a52d7
Once you have copied the MD5 codes delete the file tmp.asp!!!
Since the above technique has a microscoric security flaw (unless you have a private IIS server to use) you can also use the MD5 calculator on this site...
From which you can copy the MD5 Hashes and paste them in the appropriate places in Login.asp and paste the Username hash to the tops of the files you wish to secure.
The secured files can now only be accessed by logging in.
Once you have logged in you don't need to re-log in unless you close all your browser windows.
Visitor Counter
There are plenty of hit counters available - counting hits on a site isn't very difficult, or very useful...
What you really want to know is how many individuals have been to particular pages so that you can monitor which pages are the most popular.
This is a service that you can pay for... or you can use the method I use...
If you can persuade the folk who host your web site to give you a folder with write access in a private area you should be able to get the MAC address of the network card the user is using to access your web site.
The MAC address is a totally unique number - all the network card manufacturers make sure that no two network cards end up with the same MAC address.
This is the only way to uniquely identify the PC that looked at a particular page.
Download MAC.htm then save the text to MAC.asp and adjust a few things that should be fairly obvious...
You'll probably still need to read on to get the rest of the method.
....This web host won't allow folders with write access for "security reasons" so all thats left is to use cookies if the user has them enabled...
You'd think that you could use the IP Address of the user accessing your web pages but companies use routers which have one IP Address but possibly thousands of PCs behind them - so IP Addresses aren't terribly useful for corporate sites.
So all you can easily record is visits by people who have cookies enabled and hits.
But another problem is that search engines use 'Spiders' or 'Robots' which also trigger normal hit-counters...
These hits are of no interest - so we want to ignore them.
So heres the solution I devised:
Links to pages that I want to monitor are altered to use an ASP page which will count the hit and then redirect back to the file the user wants to see.
By 'count the hit' I mean that the ASP file tries to store a tiny cookie on the users PC which holds the Path of the file its about to redirect to and its 'Last Modified' Date.
When the user clicks the link HitsCounter.asp is called with the Target file path as a parameter.
<a href="/Shared/HitCounter.asp?Target=/MyFolder/MyObject.htm">
HitCounter.asp tries to read a cookie with the appropriate Target Path.
If it succeeds we know the user has cookies enabled - but they've already visited so we just increment the number of Hits.
If no cookie is found for this Target it tries to add one.
It then tries to re-read what it wrote to see if the user has cookies enabled.
If it still doesn't read anything the user doesn't have cookies enabled so we can only increment the number of Hits.
If it does read something then this is the first time the user has looked at the Target - and they have cookies enabled, so we increment the number of Hits and the number of visits.
After all this HitCounter.asp redirects to the Target to show the user what they wanted to see.
Download HitCounter.htm then save the text to HitCounter.asp.
Of course you'll also need the Access Database (this one is Access '97):
Finally you'll need something to view your database:
This code uses /Shared/BKOrang2.gif
as an image to use for a bar chart.
Any small square .gif will do.
Heres an example of the output
Files that have been hit today get their dates background set to blue.
The right-most column shows the change in rank since you last viewed:
Files that have become more popular get green backgrounds and positive numbers (rows up)
Files that have become less popular get red backgrounds and negative numbers (rows down)
It also allows you to reset the counts by deleting records.
This viewer is a little more complex than I could have given you but its necessary to be able to delete records when you loose interest in or delete a Target file.
The code to allow the users to check if files recorded by the Hit Counter have been updated is in the following file.
It shows them all the files they've visited, and marks updated files. It also allows them to delete the cookie for any file.
RC4 Encryption
Heres a little function to help you encrypt strings.
The Encode and Decode are performed by the same function.
The file is a working example, you only need the RC4 function in your own pages.
You can run this code by clicking here.
If anyone thinks its worth me maintaining or updating any of the above, please e-mail me.