home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a114 / 2.img / TOOLKIT / TOOLKIT.ZIP / GETPASS.SC < prev    next >
Encoding:
Text File  |  1990-08-25  |  2.6 KB  |  64 lines

  1. ; Copyright (c) 1987-1989 Borland International.  All Rights Reserved.
  2. ;
  3. ; General permission to re-distribute all or part of this script is granted,
  4. ; provided that this statement, including the above copyright notice, is not
  5. ; removed.  You may add your own copyright notice to secure copyright
  6. ; protection for new matter that you add to this script, but Borland
  7. ; International will not support, nor assume any legal responsibility for,
  8. ; material added or changes made to this script.
  9. ;
  10. ; Revs.:  MJP 2/29/88, DCY 12/12/88
  11. ; ****************************************************************************
  12. ; GetPassword accepts an alphanumeric string from a user but allows you to
  13. ; specify which characters (if any) to display on the screen as a user types.
  14. ;
  15. ; Note that GetPassword requires a user to enter a value or press [Esc].  If
  16. ; the user presses [Esc], GetPassword returns a null ("") string.  Otherwise
  17. ; it returns the string a user entered.
  18. ;
  19. ; GetPassword requires two arguments:
  20. ;
  21. ;      MaxLen: Maximum length of string to accept
  22. ;    EchoChar: Character(s) to be displayed upon each keystroke
  23. ;
  24. ; NOTE: GetPassword accepts a string at the current canvas cursor position.
  25. ;       Since it does not support wrap-around, make sure the string you
  26. ;       request from a user will fit entirely on the current line.
  27. ;
  28. Proc GetPassword(MaxLen,EchoChar)
  29.    Private;MaxLen,       ;Maximum acceptable string length
  30.           ;EchoChar,     ;Character(s) to display upon each keystroke
  31.            Pass,         ;Current string as entered by user
  32.            Char          ;Last keystroke entered
  33.  
  34.    Pass = ""
  35.    Char = GetChar()
  36.    While (Char <> 13 or IsBlank(Pass)) and Char <> 27 ;Accept until ENTER or ESC
  37.       Switch
  38.          Case Char = 127 :            ;CtrlBackspace
  39.             @ Row(),Col()-Len(Pass)*Len(EchoChar)
  40.             ?? Spaces(Len(Pass)*Len(EchoChar))
  41.             @ Row(),Col()-Len(Pass)*Len(EchoChar)
  42.             Pass = ""
  43.          Case Char > 31 and Len(Pass) < MaxLen :   ;Acceptable character
  44.             ?? EchoChar
  45.             Pass = Pass+Chr(Char)
  46.          Case Char = 8 and Match(Pass,"..@",Pass) :   ;Backspace
  47.             @ Row(),Col()-Len(EchoChar)
  48.             ?? Spaces(Len(EchoChar))
  49.             @ Row(),Col()-Len(EchoChar)
  50.          Case Char = 13 :
  51.             Message "Please enter a password"
  52.          Otherwise :                                ;Illegal character
  53.             Beep
  54.       Endswitch
  55.       Char = GetChar()
  56.    Endwhile
  57.  
  58.    If Char = 27
  59.       Then Return ""
  60.       Else Return Pass
  61.    Endif
  62.  
  63. Endproc
  64.