The QBasic / QB64 Discussion Forum      Other Subforums, Links and Downloads
 
  << Previous Topic | Next Topic >>Return to Index  

Input password, compare it with text file, write to BIN, compare with BIN.

May 13 2005 at 11:29 AM
  (Login MCalkins)
R

'First part copied and modifed from Jeff's post.
'The rest written by Michael Calkins

CLS
DIM BINcomp AS STRING * 20
DIM BINpass AS STRING * 20

PRINT "Enter password: ";
curLine% = CSRLIN 'current line
curColm% = POS(0) 'current column
LOCATE , , 1 'display cursor
DO
 password$ = INPUT$(1)
 IF password$ = CHR$(13) THEN EXIT DO
 LOCATE curLine%, curColm%, 0 'move cursor to orignal position
 IF password$ = CHR$(8) AND LEN(pwrd$) > 0 THEN
  pwrd$ = LEFT$(pwrd$, LEN(pwrd$) - 1)
 END IF
 IF ASC(password$) > 31 AND ASC(password$) < 128 THEN 'define valid chars here
  pwrd$ = pwrd$ + password$
 END IF
 PRINT STRING$(LEN(pwrd$), "*");
 tmpL% = CSRLIN
 tmpC% = POS(0)
 PRINT " "; 'space afterward for backspace
 LOCATE tmpL%, tmpC%, 1
LOOP
PRINT
LOCATE , , 0 'hide cursor
PRINT "Your password is '"; pwrd$; "'"
PRINT

OPEN "password.txt" FOR INPUT AS 1
LINE INPUT #1, text$
CLOSE
PRINT "From text file: '"; text$; "'"
IF text$ = pwrd$ THEN
 PRINT "TRUE"
ELSE
 PRINT "FALSE"
END IF
PRINT

GOSUB WriteBin 'write it
PRINT
GOSUB ReadBin 'read and compare

SYSTEM 'end the program here

WriteBin: 'a subroutine to write an obscured password.
 tmp$ = ""
 FOR i% = 1 TO LEN(pwrd$)
  tmp$ = tmp$ + CHR$(ASC(MID$(pwrd$, i%, 1)) XOR &H55) 'obscure
 NEXT i%
 BINpass = tmp$ 'force to 20 bytes.
 OPEN "password.bin" FOR BINARY AS 1
 'Be very careful not to overwrite important files!!
 PUT 1, , BINpass 'write binary to file
 CLOSE
 PRINT "Password obscured in binary file"
RETURN 'end subroutine

ReadBin: 'a subroutine to read an obscured password.
 tmp$ = ""
 FOR i% = 1 TO LEN(pwrd$)
  tmp$ = tmp$ + CHR$(ASC(MID$(pwrd$, i%, 1)) XOR &H55)
 NEXT i%
 OPEN "password.bin" FOR BINARY AS 1
 GET 1, , BINpass 'read binary from file
 CLOSE
 BINcomp = tmp$ 'force to 20 bytes.
 PRINT "From BIN file: '"; BINpass; "'"
 PRINT " compare with: '"; BINcomp; "'"
 IF BINcomp = BINpass THEN
  PRINT "TRUE"
 ELSE
  PRINT "FALSE"
 END IF
RETURN 'end subroutine

 
 Respond to this message   
Current Topic - Input password, compare it with text file, write to BIN, compare with BIN.
  << Previous Topic | Next Topic >>Return to Index  

Newbies usually go to www.qbasic.com and click on The QBasic Forum
Forum regulars have their own ways, which include The QBasic Community Forums