O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.6. Making a Password Input Field

Problem

You want to create an input text field so that characters entered into it are displayed as asterisks—a feature commonly used on password input fields.

Solution

Set the text field’s password property to true.

Discussion

When a user enters a password into a field, you generally do not want observers to be able to read the password. This is a basic security precaution. The common convention is to display only asterisks in the field as the user types. This way, the user can see that he is successfully entering a value without observers being able to easily read the password.

To create an input field that is automatically masked with asterisks, you only need to set the TextField .password property to true:

myTextField.password = true;

When you set the password property to true, all text entered into the text field, either programmatically or by user input, displays as asterisks:

myTextField.password = true;
myTextField.text = "some text";  // Text field displays: *********

See Also

Recipe 8.5. Password text fields only obscure the display of the text; the value contained by the text property is unaltered. Therefore, when you send the password value across an Internet connection, it is not encrypted. If you need additional security when sending the password, you should use HTTPS or use an encryption technique such as a cryptographic hash algorithm, as Branden Hall discusses at http://www.macromedia.com/desdev/mx/flash/extreme/extreme003.html. Also, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required