3. Description of script
The goal is to restrict access to a document (or documents) by
making it necessary to enter the name of the file (HTML page) in order to open the page.
To ensure restriction of access to a given section (HTML page) make sure that there are
no other ways to access the site (link, menu, etc.) The level of protection is minimum but
the user must know the password which is in fact the filename of the page to be loaded
(the filename without the extension is the password).
To encode the password, you use the <INPUT> element. This element is set to
display characters as asterisk (*) by setting the TYPE attribute to
password: TYPE="password".
The procedure used [checkPswd(ext)] employs a conditional instruction (if) to
verify that the contents of the <INPUT> element which is set for a password, is not
a null value (document.pswdForm.pswd.value == null) or empty (document.pswdForm.pswd.value
== '').
If this is the case, an alert message is displayed: this is achieved with the alert()
method of the window object, which we saw earlier: [alert('Invalid
password.')].
If the opposite is true (else), the script changes the location property of
the Window object in order to load the desired HTML page [this.location.href =
document.pswdForm.pswd.value + ext;] by using the value entered in the password field
(document.pswdForm.pswd.value) as a URL address of the document, to which it adds
(+ operator) the corresponding extension (in this case '.html'). The
assistant specified the extension and supplied it as the argument for the checkPswd('.html')
procedure.
This is the reason why you are asked to enter the file name without the extension
(html, htm...).
Finally, the "onClick" button event triggers the verification function and
then loads the page[checkPswd()].
|