Tutorial name: Password Masking
Written by: K. Natraj,
Difficulty Level: intermediate
Requirements: Flash MX
Download FLA

Hello friends, you might until now creating password protected flash files but there is no way that we can mask the password which the user is typing into the password field. The other user can easily get access to the password by seeing on the screen what the password is being typed, this is a very grave fault if you are designing a application where you are giving access to some data based on the password the user has keyed in. To over come this fault we have to mask whatever the user is typing in the password field. Here I will tell you a simple way to mask the password which the user is keying in. You can download the source file to view what I have done.



First open a blank flash file in that you place to text fields (Not UI components). Make the text type of these fields as Input Text, name one of them as passwordIB (which will be the text field where the user keys in the password) and give a variable name as passwordText to it. Name the second text field as passwordIBIV this is required to store the password the user has keyed in (you can use a variable instead) and give a variable name as passwordTextIV. Place the second text field out of the scene so that when the movie is running the text field is not seen. On in the first frame place the following code.

//This code is for setting the focus for input in the text
//field
Selection.setFocus(_root.passwordIB);
//This event is for the text field where the user keys in
//the password
passwordIB.onChanged = function() {
        //store the password in a variable
        txt = passwordIB.text;
        //take the last letter keyed in the password
        stxt = txt.substr(txt.length-1, 1);
        //place it in the other text field
        passwordTextIV = passwordTextIV add stxt;
        //Check if it is the first letter keyed in
        if (txt.length == 1) {
                //replace the letter with some masking letter
                passwordText = "#";
        } else {
                //if the keyed letter is not the first letter
                //take the last letter keyed in
                rtxt = txt.substr(0, txt.length-1);
                //replace the letter with some masking letter with the
                //previous masked keyed letters
                passwordText = rtxt add "#";
        }
};

test the movie to see the effect of this code.