官术网_书友最值得收藏!

Masking user passwords

When users enter their password, it should not be visible to anyone who might happen to be looking over the user's shoulder. This is an expected level of security. As shown in the following screenshot, not masking the password is unacceptable. This recipe shows you a method of masking the user's password as it is entered.

How to do it...

To accomplish our task, we will create two labels (one for the username and one for the password), three text entry fields (one for the username, a second for the unmasked password, and the third for the masked password). The masked password is the one we want displayed on the screen:

  1. Create a Username: label for content.
  2. Create a Password: label for content.
  3. Create a text entry field and name it fldUsername.
  4. Create a text entry field and name it fldMaskedPassword.
  5. Create a text entry field and name it fldUnmaskedPassword. Set this field's visible property to false.
  6. Add the following code to the fldMaskedPassword field:
    on keydown pKey
      put the text of fld "fldUnmaskedPassword" into tRaw
      put the text of fld "fldMaskedPassword" into tMask
      
      put tRaw & pKey into fld "fldUnmaskedPassword"
      put tMask & "*" into fld "fldMaskedPassword"
    end keydown
  7. When the user selects the Log In button, you will pull his/her username and password with statements such as the following:
    the text of fld "fldUsername"
    the text of fld "fldUnmaskedPassword"

How it works...

To achieve our desired results, we created an invisible text field in order to hold the user's actual password as it is entered. As each key was pressed, the key was echoed to the hidden field and displayed as * in the visible password field.

There's more...

If you are implementing this password-masking function in your mobile apps, you will want to thoroughly test it and ensure that you take into account user actions such as using the Backspace, Delete, and other keys. Once you have it working the way you want it, you might consider asking your friend to bug test it for you. It can be fun for people to "try and break" your app.

主站蜘蛛池模板: 佛教| 新巴尔虎右旗| 巢湖市| 南岸区| 南乐县| 长垣县| 滁州市| 普兰店市| 泾阳县| 中牟县| 乳源| 苍山县| 富蕴县| 桂平市| 新宾| 岳西县| 铁力市| 张家界市| 武川县| 祁东县| 水富县| 昌黎县| 吉安县| 南充市| 青海省| 锡林郭勒盟| 大悟县| 驻马店市| 田林县| 和平县| 宜都市| 昆明市| 江孜县| 瓮安县| 古蔺县| 巩义市| 郸城县| 平谷区| 会宁县| 定日县| 凤阳县|