home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / basic / bmag / password.bas < prev    next >
Encoding:
BASIC Source File  |  1994-04-27  |  3.6 KB  |  110 lines

  1. '─ Area: F-QUICKBASIC ─────────────────────────────────────────────────────────
  2. '  Msg#: 383                                          Date: 25 Apr 94  15:40:02
  3. '  From: Robert Fortune                               Read: Yes    Replied: No 
  4. '    To: Raymund Miculob                              Mark:                     
  5. '  Subj: Password
  6. '──────────────────────────────────────────────────────────────────────────────
  7. '  Purpose - Get name and password from user. Allows user 3 Tries at
  8. '  password. To change this code to ask for name & password on
  9. '  different lines, change Row% in the following line from Row% = 4 to
  10. '  the line number you want (less than 20 is best).
  11. '  Change Column% = 1 to start prompts in different columns.
  12.  
  13. DECLARE SUB BackSpace (Text$)
  14. Row% = 4                 '  line where input prompts start
  15. Column% = 1              '  column where input prompts start
  16. Temp% = Column%          '  backup of column% variable
  17. Min% = 4                 '  min length a users full name must be
  18. Max% = 30                '  max length a users full name can be
  19. Prompt1$ = "Logon:["     '  username prompt
  20. Prompt2$ = "Password: "  '  password prompt
  21. PassLen% = 15            '  max length of legal passwords
  22. ValidPass$ = "HELLO"     '  secret valid user password
  23. Tries% = 3               '  number of attempts at password permitted
  24.  
  25. REM Get the User's full name
  26. CLS
  27. LOCATE Row%, Column%
  28. PRINT Prompt1$ + SPACE$(Max%) + "] ";
  29. Column% = Column% + LEN(Prompt1$)
  30. DO
  31.    LOCATE Row%, Column%, 1
  32.    DO
  33.      UserKey$ = INKEY$
  34.    LOOP UNTIL LEN(UserKey$)     ' wait for a keypress
  35.    UK% = ASC(UserKey$)
  36.  
  37. ' backspace key pressed
  38.    IF (UK% = 8) AND (LEN(UserName$) > 0) THEN
  39.       CALL BackSpace(UserName$)
  40.    END IF
  41.  
  42. ' accept A-Z or a-z or a SPACE or a ' for Irish type names as valid chars
  43.    IF ((UK% > 64) AND (UK% < 91)) OR ((UK% > 96) AND (UK% < 123)) OR (UK% = 39)
  44.       IF LEN(UserName$) = Max% THEN ' username too long
  45.          CALL BackSpace(UserName$)
  46.          BEEP
  47.       END IF
  48.       UserName$ = UserName$ + UserKey$
  49.       PRINT UserKey$;
  50.       Column% = Column% + 1
  51.    END IF
  52. LOOP UNTIL (UK% = 13) AND (LEN(UserName$) >= Min%)
  53. UserName$ = LTRIM$(RTRIM$(UserName$))
  54. PRINT
  55.  
  56. ' Now get the user password
  57. Row% = Row% + 1
  58. Column% = Temp%
  59. LOCATE Row%, Column%
  60. PRINT Prompt2$;
  61. FOR I% = 1 TO Tries%    '  number of tries permitted to enter password
  62.   Column% = Temp% + LEN(Prompt2$)
  63.   LOCATE Row%, Column%
  64.   PRINT SPACE$(79 - (Column% + LEN(Prompt2$)));
  65.   LOCATE Row%, Column%, 1
  66.   PassWord$ = ""
  67.   DO
  68.     DO
  69.       UserKey$ = UCASE$(INKEY$)
  70.     LOOP UNTIL LEN(UserKey$)     ' wait for a keypress
  71.     UK% = ASC(UserKey$)
  72.  
  73. ' backspace key pressed?
  74.     IF (UK% = 8) AND (LEN(PassWord$) > 0) THEN
  75.        CALL BackSpace(PassWord$)
  76.     END IF
  77.  
  78. ' build users password
  79.     IF (UK% > 32) AND (UK% < 127) THEN
  80.        Column% = Column% + 1
  81.        PRINT "*";
  82.        PassWord$ = PassWord$ + UserKey$
  83.     END IF
  84.   LOOP UNTIL (UK% = 13) OR (LEN(PassWord$) > PassLen%)
  85.  
  86.   IF PassWord$ = ValidPass$ THEN  ' we have a valid password
  87.      PRINT
  88.      PRINT "Welcome to my world!"
  89.      EXIT FOR
  90.   ELSE
  91.      Column% = Column% + 2     ' invalid password entry
  92.      LOCATE Row%, Column%      ' flash em an error message (+16)
  93.      COLOR 12 + 16
  94.      PRINT "*Invalid Password*"
  95.      BEEP
  96.      SLEEP 2
  97.      COLOR 7                   ' reset foreground color to white
  98.   END IF
  99. NEXT I%
  100. SUB BackSpace (Text$)
  101. SHARED Row%, Column%
  102.       J% = LEN(Text$) - 1
  103.       Text$ = LEFT$(Text$, J%)
  104.       Column% = Column% - 1
  105.       LOCATE Row%, Column%
  106.       PRINT " ";
  107.       LOCATE Row%, Column%
  108. END SUB
  109.  
  110.