/Home/H2O Sample Code/Multi-Staff Login
Writing a login page from scratch is done by adding a
macro at the bottom of your login page. This code is a good
example of a simple login page that reads its login-password
pairs from a text file.
The top of the file defines the file name that stores your login-password
pairs. This is followed by the HTML Form of your login page. Note how
the form is linked to the on-click Overlay (macro) that checks the
login file for a valid login-password pair.
The Onclick Overlay
The COPY function is used to load the data. Note the specification of
the table delimiter (TS=","). This is needed since the file is comma-delimited (also known as CSV). The COPY function lopads the file into the array
checkpassword. Then the function GETCOLEQ is used to find only those
lines where column 1 equals the login name specified. Then an IF statement
is used to see if the line found (stored in the variable checkpassword)
has the password in its second column, as it should, if the login-password
pair specified was correct.
| login.html |
<<
loginfile="users.txt"
welcomepage="menu.html"
>>
<html>
<title>Mulit-Staff Login</title>
<<
IF errmessage <> "ERROR" DO
DISPLAY '<font color=red><b>' + errmessage +
'</b></font><br><br>'
/DISPLAY
errmessage = "ERROR"
/IF
>>
<form method=post action=checkpassword><br>
Name:
<input type=text size=30 name=multicheckname><br>
Password:
<input type=password size=30 name=multicheckpassword>
<input type=submit value="Enter">
</form>
</html>
<<OVERLAY checkpassword
# load login,password pairs from file /#
IF multicheckname="" THEN
errmessage = "Bad Login."
GOTO PAGE
/IF
COPY FILE=loginfile TS="," TO checkpassword /COPY
checkpassword = GETCOLEQ(checkpassword,1,multicheckname)
IF checkpassword = "" THEN
errmessage = "Bad Login."
GOTO PAGE
/IF
IF multicheckpassword != checkpassword[2,1] THEN
errmessage = "Bad Login."
GOTO PAGE
/IF
accesslevel = checkpassword[3,1]
GOTO welcomepage
>>
|
|
NOTE: The users.txt file is assumed to be comma-delimited. The login IDs
are stored in clolumn 1 and the passwords are stored in column 2. For example:
jsmith,mypassword
achen,mypassword2
bbabson,mypassword3
admin,mypassword4
jjackson,mypassword5
wpeter,password6
|