Add Password Protection

  • Konuyu başlatan Konuyu başlatan guclusat
  • Başlangıç Tarihi Başlangıç Tarihi

guclusat

Tanınmış Üye
Süper Moderatör
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:
Kod:
-- 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:
Kod:
--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 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
 
Geri
Yukarı