How do I...?

Add Password Protection

There are many instances requiring the user to be prompted for information that must not be visible on the screen, such as a password. In AutoPlay Media Studio this is accomplished by using a Dialog.PasswordInput action.

As an example, we will prompt the user for a password at the start of your program, and compare it to a stored value (thereby limiting access to your program to only those who know the password).

To accomplish this:

  1. Insert the following script in your page's On Show event:

-- the 'correct' password
real_password = "password";

-- prompt the user to enter a password
user_password = Dialog.PasswordInput("Password", "Please enter the password: ", MB_ICONQUESTION);

-- compare the user's password to the 'correct' password.
-- If the user supplies the wrong password, exit the program.
if real_password ~= user_password then
    Application.Exit();
end

This script pops up a dialog box requesting the password. Whatever the user types in this dialog box appears as *******. If the correct password is entered, the program runs normally. If any other password is entered, the program will close.

Alternatively, you can have a 'list' of valid passwords.   To accomplish this, store your valid passwords in a table:

  1. Insert the following script in your page's On Show event:

--assume the user enters a bad password
correct_password = false;

-- the 'correct' password
real_passwords = {"password", "password2", "3rdPassword"};

-- prompt the user to enter a password
user_password = Dialog.PasswordInput("Password", "Please enter the password: ", MB_ICONQUESTION);

-- compare the user's password to the 'correct' password.
for j in pairs(real_passwords) do
    if real_passwords[j] == user_password then
        correct_password = true;
    end
end

--if the password was bad, exit
if not correct_password then
    Application.Exit();
end

Tip: As a slight variation of this technique, you can store your password list in a text file, and when your application is run, populate a table with the contents of that text file.  For an example of reading a text file to a table, see How do I read specific lines from a text file.