Loading ...
Sorry, an error occurred while loading the content.

28986AW: [libertybasic] NEED HELP! (EOF password troubles)

Expand Messages
  • pendl2megabit
    Dec 1, 2005
      You had several errors in your code:

      1) EOF is a function: EOF(#FileHandle)
      2) reading the file during the password check,
      will not evaluate all entries to all combinations
      If you enter the correct combination on the second attempt,
      but it is the first entry in the file, you won't get access

      What I changed:

      1) create an empty password file, if the program is run for the
      first time, because OPEN FOR INPUT will crash, if the file
      does not exist
      2) filled an array to hold all combinations, so we can check
      all combinations for any of the three attempts
      3) introduced flags to signal a correct combination
      4) corrected the way a new combination is written to the password file

      Some things to consider:

      1) only allow a new user to be entered, if the access was granted.
      2) if the username or password includes a comma, your program won't work

      Code follows;-)

      Stefan Pendl

      '---code start
      ' if the password file does not exist
      ' create an empty file
      OPEN "password.txt" FOR APPEND AS #1
      close #1

      ' fill an array with all passwords
      OPEN "password.txt" FOR INPUT AS #1
      WHILE not(EOF(#1))
      INPUT #1, name2$, pass2$
      passcount = passcount + 1

      ' you must predimension the array, if it exceeds 10 elements
      allpass$(passcount,1) = name2$
      allpass$(passcount,2) = pass2$
      close #1

      INPUT "Enter Username: "; name$
      INPUT "Enter Password: "; pass$

      tries = tries + 1
      correctname = 0
      correctpass = 0

      for count = 1 to passcount
      if name$ = allpass$(count, 1) then
      correctname = 1

      if pass$ = allpass$(count, 2) then
      correctpass = 1
      end if
      end if

      if correctname = 0 and correctpass = 0 then
      PRINT "Incorrect username and password."
      end if

      if correctname = 1 and correctpass = 0 then
      PRINT "Incorrect password."
      end if
      loop until (correctname = 1 and correctpass = 1) or tries = 3

      if correctname = 1 and correctpass = 1 then
      PRINT "Access granted."
      GOSUB [start3]
      END IF

      print "Access denied, create new username - password combination"

      OPEN "password.txt" FOR APPEND AS #1
      INPUT "Enter new username: "; newname$
      INPUT "Enter password: "; newpass$
      PRINT #1, newname$; ","; newpass$
      CLOSE #1
      '---code end

      > -----Urspr√ľngliche Nachricht-----
      > Von: libertybasic@yahoogroups.com
      > Ok, it works on the second attempt now, but when I try the third, it
      > seems to just ignore my if/then statements and keeps asking for
      > username/password.

      Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de
    • Show all 7 messages in this topic