home *** CD-ROM | disk | FTP | other *** search
- '─ Area: F-QUICKBASIC ─────────────────────────────────────────────────────────
- ' Msg#: 383 Date: 25 Apr 94 15:40:02
- ' From: Robert Fortune Read: Yes Replied: No
- ' To: Raymund Miculob Mark:
- ' Subj: Password
- '──────────────────────────────────────────────────────────────────────────────
- ' Purpose - Get name and password from user. Allows user 3 Tries at
- ' password. To change this code to ask for name & password on
- ' different lines, change Row% in the following line from Row% = 4 to
- ' the line number you want (less than 20 is best).
- ' Change Column% = 1 to start prompts in different columns.
-
- DECLARE SUB BackSpace (Text$)
- Row% = 4 ' line where input prompts start
- Column% = 1 ' column where input prompts start
- Temp% = Column% ' backup of column% variable
- Min% = 4 ' min length a users full name must be
- Max% = 30 ' max length a users full name can be
- Prompt1$ = "Logon:[" ' username prompt
- Prompt2$ = "Password: " ' password prompt
- PassLen% = 15 ' max length of legal passwords
- ValidPass$ = "HELLO" ' secret valid user password
- Tries% = 3 ' number of attempts at password permitted
-
- REM Get the User's full name
- CLS
- LOCATE Row%, Column%
- PRINT Prompt1$ + SPACE$(Max%) + "] ";
- Column% = Column% + LEN(Prompt1$)
- DO
- LOCATE Row%, Column%, 1
- DO
- UserKey$ = INKEY$
- LOOP UNTIL LEN(UserKey$) ' wait for a keypress
- UK% = ASC(UserKey$)
-
- ' backspace key pressed
- IF (UK% = 8) AND (LEN(UserName$) > 0) THEN
- CALL BackSpace(UserName$)
- END IF
-
- ' accept A-Z or a-z or a SPACE or a ' for Irish type names as valid chars
- IF ((UK% > 64) AND (UK% < 91)) OR ((UK% > 96) AND (UK% < 123)) OR (UK% = 39)
- IF LEN(UserName$) = Max% THEN ' username too long
- CALL BackSpace(UserName$)
- BEEP
- END IF
- UserName$ = UserName$ + UserKey$
- PRINT UserKey$;
- Column% = Column% + 1
- END IF
- LOOP UNTIL (UK% = 13) AND (LEN(UserName$) >= Min%)
- UserName$ = LTRIM$(RTRIM$(UserName$))
- PRINT
-
- ' Now get the user password
- Row% = Row% + 1
- Column% = Temp%
- LOCATE Row%, Column%
- PRINT Prompt2$;
- FOR I% = 1 TO Tries% ' number of tries permitted to enter password
- Column% = Temp% + LEN(Prompt2$)
- LOCATE Row%, Column%
- PRINT SPACE$(79 - (Column% + LEN(Prompt2$)));
- LOCATE Row%, Column%, 1
- PassWord$ = ""
- DO
- DO
- UserKey$ = UCASE$(INKEY$)
- LOOP UNTIL LEN(UserKey$) ' wait for a keypress
- UK% = ASC(UserKey$)
-
- ' backspace key pressed?
- IF (UK% = 8) AND (LEN(PassWord$) > 0) THEN
- CALL BackSpace(PassWord$)
- END IF
-
- ' build users password
- IF (UK% > 32) AND (UK% < 127) THEN
- Column% = Column% + 1
- PRINT "*";
- PassWord$ = PassWord$ + UserKey$
- END IF
- LOOP UNTIL (UK% = 13) OR (LEN(PassWord$) > PassLen%)
-
- IF PassWord$ = ValidPass$ THEN ' we have a valid password
- PRINT
- PRINT "Welcome to my world!"
- EXIT FOR
- ELSE
- Column% = Column% + 2 ' invalid password entry
- LOCATE Row%, Column% ' flash em an error message (+16)
- COLOR 12 + 16
- PRINT "*Invalid Password*"
- BEEP
- SLEEP 2
- COLOR 7 ' reset foreground color to white
- END IF
- NEXT I%
- SUB BackSpace (Text$)
- SHARED Row%, Column%
- J% = LEN(Text$) - 1
- Text$ = LEFT$(Text$, J%)
- Column% = Column% - 1
- LOCATE Row%, Column%
- PRINT " ";
- LOCATE Row%, Column%
- END SUB
-
-