Consultor Eletrônico



Kbase P18033: How to display asterisks ("*") in a BLANK fill-in for passwords?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   24/11/2005
Status: Verified

GOAL:

How to display asterisks ("*") in a BLANK fill-in for passwords?

FACT(s) (Environment):

Progress 8.x
Progress 9.x

FIX:

Most Microsoft Windows applications will display asterisks ("*") in password fields as the user types in a password. This cues the user as to how many characters have been input while keeping the password secret.

In older releases of Progress there is no native support for this, but it is possible to implement a fill-in to do the same thing. The trick is use a fill-in widget which is *not* directly associated with the password variable. Instead, the fill-in acts as a kind of place-holder to show the string of asterisks, while another variable keeps track of the actual password string.

In the example below, the variable pword is the actual password variable, while fill-in-1 acts to display the proper number of asterisks. There is also a Quit button defined for the frame.


DEF VAR pword AS CHAR NO-UNDO.

DEFINE BUTTON btn-Quit AUTO-END-KEY
LABEL "QUIT"
SIZE 9.72 BY 1.17.

DEFINE VARIABLE fill-in-1 AS CHARACTER FORMAT "X(256)":U
LABEL "Password"
VIEW-AS FILL-IN
SIZE 22 BY 1 NO-UNDO.

DEFINE FRAME frame-a
fill-in-1 AT ROW 6 COL 10 COLON-ALIGNED
btn-Quit AT ROW 10 COL 12
WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY
SIDE-LABELS NO-UNDERLINE THREE-D
AT COL 1 ROW 1
SIZE 82 BY 22.


ON ANY-KEY OF fill-in-1 IN FRAME frame-a DO:

CASE KEYFUNCTION(LASTKEY):

WHEN "DELETE-CHARACTER" THEN DO:
/* Remove last char from password and last "*" from fill-in. */
IF LENGTH(pword) > 0 THEN DO:
pword = SUBSTRING(pword,1,(LENGTH(pword) - 1)).
fill-in-1:SCREEN-VALUE =
SUBSTRING(fill-in-1:SCREEN-VALUE,1,
LENGTH(fill-in-1:SCREEN-VALUE) - 1).
fill-in-1:CURSOR-OFFSET = LENGTH(fill-in-1:SCREEN-VALUE) + 1.
RETURN NO-APPLY.
END.
END.

WHEN "BACKSPACE" THEN DO:
/* Remove last char from password and last "*" from fill-in. */
IF LENGTH(pword) > 0 THEN DO:
pword = SUBSTRING(pword,1,(LENGTH(pword) - 1)).
fill-in-1:SCREEN-VALUE =
SUBSTRING(fill-in-1:SCREEN-VALUE,1,
LENGTH(fill-in-1:SCREEN-VALUE) - 1).
fill-in-1:CURSOR-OFFSET = LENGTH(fill-in-1:SCREEN-VALUE) + 1.
RETURN NO-APPLY.
END.
END.

WHEN "RETURN" THEN DO:
/* User believes password is correct -- validate password. */

/* Your validation code here. */

RETURN NO-APPLY.
END.

WHEN "TAB" THEN DO:
/* User believes password is correct -- validate password. */

/* Your validation code here. */

RETURN NO-APPLY.
END.

WHEN "END-ERROR" THEN DO:

/* END-ERROR */
APPLY "CHOOSE" TO btn-Quit IN FRAME frame-a.
RETURN NO-APPLY.
END.

OTHERWISE DO:
/* check for printable character */
IF KEYCODE(KEYFUNCTION(LASTKEY)) > 0 AND
KEYCODE(KEYFUNCTION(LASTKEY)) < 200
THEN DO:
/* Build password from input & display "*" in fill-in. */
pword = pword + KEYFUNCTION(LASTKEY).
fill-in-1:SCREEN-VALUE = fill-in-1:SCREEN-VALUE + "*".
fill-in-1:CURSOR-OFFSET = fill-in-1:CURSOR-OFFSET + 1.
RETURN NO-APPLY.

END.
ELSE RETURN NO-APPLY. /* ignore non-printables */
END.

END CASE.

END.
/* main block */
ENABLE ALL WITH FRAME frame-a.
WAIT-FOR WINDOW-CLOSE OF current-window.