home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / PDXOS2-1.ZIP / SAMPLE / GETPASS.SC < prev    next >
Encoding:
Text File  |  1988-12-29  |  2.0 KB  |  49 lines

  1. ; Contains Licensed Material Copyright (C) 1987 Ansa Software -- MJP
  2.  
  3. ; This procedure will accept an alphanumeric string.  It differs from the
  4. ; ACCEPT command in that it doesn't display the string as it is being entered,
  5. ; but rather displays user-definable characters.
  6. ;
  7. ; The procedure is called by invoking the command:  GetPassword(MaxLen,DispKey),
  8. ; where MaxLen is the maximum length of the string to be accepted and DispKey
  9. ; the character string to be displayed after each keystroke.  If no string is
  10. ; entered (ESC is pressed) then GetPassword will return a blank string.
  11. ;
  12. ; NOTE:  It is up to the programmer to make sure that the input given by the
  13. ; user will fit entirely on one line, as this procedure does not support
  14. ; wrap-around.
  15. ;
  16. Proc GetPassword(MaxLen,DispKey)
  17.    Private;MaxLen,                 ;Stores the maximum acceptable string length
  18.           ;DispKey,                ;Character(s) to display upon each keystroke
  19.            Pass,                   ;Stores the actual password
  20.            Char                    ;Stores the last keystroke entered
  21.    Pass=""
  22.    Char=getchar()
  23.    While (Char<>13 or isblank(Pass)) and Char<>27 ;Accept until ENTER or ESC
  24.       Switch
  25.          Case Char=127:            ;CtrlBackspace
  26.             @row(),col()-len(Pass)*len(DispKey)
  27.             ?? spaces(len(Pass)*len(DispKey))
  28.             @row(),col()-len(Pass)*len(DispKey)
  29.             Pass=""
  30.          Case Char>32 and len(Pass)<MaxLen:        ;Acceptable character
  31.             ?? DispKey
  32.             Pass=Pass+chr(Char)
  33.          Case Char=8 and match(Pass,"..@",Pass):   ;Backspace
  34.             @row(),col()-len(DispKey)
  35.             ?? spaces(len(DispKey))
  36.             @row(),col()-len(DispKey)
  37.          Case Char=13:
  38.             Message "The password may not be left blank."
  39.          Otherwise:                                ;Illegal character
  40.             Beep
  41.       Endswitch
  42.       Char=getchar()
  43.    Endwhile
  44.    If Char=27
  45.       Then Return ""
  46.       Else Return Pass
  47.    Endif
  48. Endproc
  49.