Since this is so popular and simple, yet people somehow still have problems getting it to work, I've also added a VBScript file you can run, which will prompt you for the username, password, and URL of the protected page.
It will then create the javascript password file for people unfamiliar with javascript. All you need to do then, is put the password file in the same directory as login.htm and auth.htm.
The URL is not validated, so if the resulting password file doesn't work, you probably typed the URL wrong.
The .zip file is attached to this message.
Just double click on the "PasswordHelper.vbs" VBScript file and follow the instructions to create your password file(s). You need to run this file locally, and then upload the password file(s) to your website.
Note: VBScript is a ©Microsoft technology, so this file will only work on Windows!
This file is safe to run. If you get any warnings, or are concerned, you can open the .vbs file with notepad, and make sure that the code matches the following:
Code:
Option Explicit
Dim UserName, Password, RedirectPage
Dim fs, f
While NOT IsAlphaNumeric(Username)
If Username <> "" AND NOT IsAlphaNumeric(Username) Then
MsgBox "Username must be alphanumeric, without spaces!",16,"Password Helper"
End If
Username = InputBox("Enter Username:","Password Helper")
Wend
While NOT IsAlphaNumeric(Password)
If Password <> "" AND NOT IsAlphaNumeric(Password) Then
MsgBox "Password must be alphanumeric, without spaces!",16,"Password Helper"
End If
Password = InputBox("Enter Password:","Password Helper")
Wend
While RedirectPage = ""
RedirectPage = InputBox("Please enter the URL of the password protected page:","Password Helper")
Wend
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(LCase(Trim(Username)) & LCase(Trim(Password)) & ".js",2,True)
f.WriteLine("auth = true;")
f.Write("redirect = """ & RedirectPage & """;")
Set f = Nothing
Set fs = Nothing
MsgBox "Password file created!",0,"Password Helper"
Function IsAlphaNumeric(str)
Dim ianRegEx
Set ianRegEx = New RegExp
ianRegEx.Pattern = "^[a-zA-Z0-9]+$"
ianRegEx.Global = True
IsAlphaNumeric = ianRegEx.Test(str)
End Function