You can use secret editors to securely obtain PINs or passwords from a user. As the user types into a secret editor, it represents each character with an asterisk on the display, as shown in Figure 8-10.
Series 60 provides two types of secret editor: a numeric one that can be used for PINs, and an alphanumeric one that can be used for passwords. Unlike the numeric secret editor, the alphanumeric one displays the character briefly before converting it into an asterisk. This is because in alphanumeric mode, each key on the keypad can produce different characters .
The code for using secret editors is quite simple and so does not require a dedicated example. This section shows how to define a secret editor in a resource, instantiate it and get and set its value.
Numeric secret editors are defined using a NUMSECRETED resource structure, and alphanumeric secret editors are defined using a SECRETED structure:
RESOURCE NUMSECRETED r_my_numeric_secret_editor { num_code_chars = 4; } RESOURCE SECRETED r_my_secret_editor { num_letters = 10; }
Each resource has a field representing the maximum length of the editor. In the NUMSECRETED resource, this is the num_code_chars field, and in the SECRETED resource, the num_letters field. The value must be less than a predefined constant, EMaxSecEdLength , otherwise the editor will panic on construction with the error code EEikPanicSecretEditorTooLong.
Secret editors can be instantiated using any of the standard methods previously seen ”for example, using ConstructFromResourceL() , or creating one as part of a dialog, in which case the dialog constructs, and owns the editor.
Secret Editor | Class | Resource | Control |
---|---|---|---|
Alphanumeric | CEikSecretEditor | SECRETED | EEikCtSecretEd |
Numeric | CAknNumericSecretEditor | NUMSECRETED | EAknCtNumericSecretEditor |
The alphanumeric secret editor class is CEikSecretEditor and the numeric secret editor class is CAknNumericSecretEditor , which is derived from CEikSecretEditor . Table 8-13 summarizes the values that you should use for each type of secret editor resource, including the control value that you should use to create the editor in a dialog.
Once constructed , you can simply get a reference to the editor's text using GetText() and initialize the contents of the editor with SetText() .