Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FPD 2.6 for DOS - Convert character typing to * (password)

Status
Not open for further replies.

Foxtech

Programmer
May 26, 2001
66
CA
hi everyone,

I know that has existed a function or procedure that allows to hide or replace with * when user types in. I don't remember what's thread number.

example:

Enter your PIN: **** (4 digits)

Here are my source codes:

@ 1,1 say 'Enter your PIN:'
@ 2,30 get m.PIN valid ChkPin(m.pin)

*** I don't want user to see the PIN when they are typing***

@ 5,1 say 'Enter your date of birth (yymm):'
@ 6,1 get m.DateBirth pict '!!!!'


Function ChkPin

Return

please advise and thanks a lot.

FoxTech
 
One way I have done it in the past is to just use the same color for foreground and background colors. The PIN/password is hidden unless the text is hi-lighted.

But here is another routine I use. Call it using something like :
Code:
SET PROCEDURE TO passproc

@ 1,1 say 'Enter your PIN:'
m.pin = password(4, 1, 16)

Here is the procedure file:
Code:
*...   PASSPROC.PRG  ...
*... This routine waits for alpha-numeric input,
*...   displays '*'s at x/y coords, then
*...   returns a character string of 'nlength'

PARAMETERS nlength, nxpos, nypos

IF TYPE('nLength') = 'L'
   nlength = 1
ENDIF

IF TYPE('nXpos') = 'L'
   nxpos = 0
ENDIF

IF TYPE('nYpos') = 'L'
   nypos = 0
ENDIF

*CLEAR

STORE .F. TO done
STORE 0 TO nKeyCode, nttllen
STORE '' TO cPassword

DO WHILE nKeyCode # 27
   nKeyCode = INKEY(0, 'HM')
   DO CASE
   	*... numpad 0-1 if numlock is off
      CASE INLIST(nKeyCode, 22, 6, 24, 3, 19, 4, 1, 5, 18)
      	do caution with "NumLock Off", "Check NumLock"

      *... number
      CASE INLIST(nKeyCode, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57)
         IF nttllen = nlength
            loop
            *done = .T.
         ENDIF
         nttllen = nttllen + 1
         cPassword = cPassword + CHR(nKeyCode)

      *... lower alpha
      CASE BETWEEN(nKeyCode, 97, 122)
         IF nttllen = nlength
            loop
            *done = .T.
         ENDIF
         nttllen = nttllen + 1
         cPassword = cPassword + CHR(nKeyCode)

      *... upper alpha
      CASE BETWEEN(nKeyCode, 65, 90)
         IF nttllen = nlength
            loop
            *done = .T.
         ENDIF
         nttllen = nttllen + 1
         cPassword = cPassword + CHR(nKeyCode)

      *... backspace
      CASE nKeyCode = 127
         nttllen = nttllen - 1
         cPassword = LEFT(cPassword, nttllen)
         IF nttllen < 1
            nttllen = 0
         ENDIF

      CASE nKeyCode = 27   &&... escape
         cPassword = ''
         done = .T.

*      CASE nKeyCode =  9   &&... tab
*         done = .T.
      
      CASE nKeyCode = 13   &&... enter
         done = .T.
      
   ENDCASE
   @ nxpos, nypos SAY PADR(REPLICATE('*', nttllen), nlength, ' ') FONT 'Foxfont', 10
   IF nttllen = nlength
   	EXIT
  	ENDIF
   IF done
      EXIT
   ENDIF

ENDDO
RETURN cPassword

*......... caution dialog  .....
PROCEDURE caution
   PARAMETERS cautitle, msgstring
   
   PUSH KEY
   ON KEY LABEL f2  *
   ON KEY LABEL f3  *
   
   IF NOT WEXIST("caution")
      DEFINE WINDOW caution ;
         AT 19.167, 15.000 ;
         SIZE 7.308,95.000 ;
         TITLE '*** ' + cautitle + ' ***';
         FONT "MS Sans Serif", 8 ;
         FLOAT ;
         NOCLOSE ;
         MINIMIZE ;
         SYSTEM ;
         COLOR RGB(,,,255,0,0)
   ENDIF ( NOT WEXIST("caution") )
   
   MOVE WINDOW caution CENTER
   
   IF WVISIBLE("caution")
      ACTIVATE WINDOW caution SAME
   ELSE
      ACTIVATE WINDOW caution NOSHOW
   ENDIF ( WVISIBLE("caution") )
   STORE WCOLS("caution")/2 TO wincenter
   STORE LEN(msgstring)/2 TO mcenter
   STORE 0 TO nothing
   
   @1, (wincenter  - mcenter) - 2 SAY msgstring;
      COLOR RGB(0,0,0,255,255,0);
      FONT "MS Sans Serif", 9 ;
      STYLE "B"
   
   @ 2.769, (wincenter  - 4.3) GET nothing ;
      PICTURE "@*HT \<Ok" ;
      SIZE 1.769,8.667,0.667 ;
      FONT "MS Sans Serif", 8 ;
      STYLE "B"
   
   READ CYCLE
   CLEAR
   DEACTIVATE WINDOW caution
   RELEASE WINDOW caution
   
   POP KEY
   RETURN


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
hi Dave,

Thanks for helping me by providing the codes.

I don't know how to apply your procedure into my actual codes.

Please help

***** here is my code *****
Clear

@ 4,1 say "PIN:" color gr+/b
@ 4,6 GET mPin PICT "XXXX" valid CHK_PIN(mPin)
@ 4,20 say "Nb. labels:" color gr+/b
@ 4,39 GET m.label PICT "99"
READ

Function CHK_PIN
Parameters mPinNo

private res_pin

m.IDUsager = space(2)

Res_pin = .F.

If mPinNo = space(04)
Store .F. to res_pin
Do mess_err with 1
Else
Sele Password
Set order to tag PIN
SEEK mPinNo
If found()
Store .T. to Res_pin
m.IDUsager = ID
Else
Do mess_err with 2
Endif
Endif
Return Res_pin

PROCEDURE Mess_Err
Parameters code
set cursor off
??chr(7)
Do case
case code = 1
wait "The PIN is blank..." window timeout 2
case code = 2
wait "The PIN is invalid..." window timeout 2
Endcase
set cursor on
Return

Return
 
Here's one way to implement it.

Copy the entire code portion in the box above, where I said: "Here is the procedure file:". Save that code into a .prg file named PASSPROC.PRG, after making one small modification I neglected to add. You will need to add the line in blue to the original file. Sorry, my bad.
Code:
*...   PASSPROC.PRG  ...
*... This routine waits for alpha-numeric input,
*...   displays '*'s at x/y coords, then
*...   returns a character string of 'nlength'
[COLOR=blue]PROCEDURE password[/color]
PARAMETERS nlength, nxpos, nypos

Next, change your code as I have done in the areas colored blue below:
Code:
***** here is my code *****
Clear
[COLOR=blue]SET PROCEDURE TO passproc[/color]
STORE 1 TO nCounter
DO WHILE .T.
   @ 4,1 say "PIN:" color gr+/b[COLOR=blue]
   *... @ 4,6  GET mPin PICT "XXXX" valid CHK_PIN(mPin)
   m.mPin = password(4, 4, 16)[/color]
   IF CHK_PIN(mPin)   &&... good pin
      EXIT
   ELSE
      *... bad pin 
      nCounter = nCounter + 1
      IF nCounter > 3  &&... attempts
         RETURN  
      ENDIF
   ENDIF
ENDDO    
@ 4,20 say "Nb. labels:" color gr+/b
@ 4,39  GET m.label PICT "99"
READ

Now, the 'nCounter' you can use or not, it just gives a safe exit from the endless DO WHILE loop.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Dave Summers have done a good job. But if you require only not to show the characters on the scree, while typeing the password. You could use color pair and use the same color for fore/background. Once done, and then set back the original colors. I used this method a long time ago. Can not remeber all the colors etc. may be something like
set color to X/B, X/B

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top