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

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

Expand Messages
  • pendl2megabit
    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
    Message 1 of 7 , Dec 1, 2005
    • 0 Attachment
      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$
      wend
      close #1

      do
      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
      next

      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."
      ELSE
      GOSUB [start3]
      END IF
      end

      [start3]
      cls
      print
      print "Access denied, create new username - password combination"
      print

      OPEN "password.txt" FOR APPEND AS #1
      INPUT "Enter new username: "; newname$
      INPUT "Enter password: "; newpass$
      PRINT #1, newname$; ","; newpass$
      CLOSE #1
      return
      '---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
    • akuma86
      Sorry I forgot to mention there is a password file I am accessing seperately. Also, with the EOF loop, it s supposed to search through my file. I ve done it
      Message 2 of 7 , Dec 1, 2005
      • 0 Attachment
        Sorry I forgot to mention there is a password file I am accessing
        seperately. Also, with the EOF loop, it's supposed to search through
        my file. I've done it before with a search engine, I just can't
        figure out why it won't work this time.

        --- In libertybasic@yahoogroups.com, "pendl2megabit"
        <pendl2megabit@y...> wrote:
        >
        > 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$
        > wend
        > close #1
        >
        > do
        > 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
        > next
        >
        > 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."
        > ELSE
        > GOSUB [start3]
        > END IF
        > end
        >
        > [start3]
        > cls
        > print
        > print "Access denied, create new username - password
        combination"
        > print
        >
        > OPEN "password.txt" FOR APPEND AS #1
        > INPUT "Enter new username: "; newname$
        > INPUT "Enter password: "; newpass$
        > PRINT #1, newname$; ","; newpass$
        > CLOSE #1
        > return
        > '---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
        >
      • pendl2megabit
        Some questions so:1) did you run your code in the debugger step-by-step? you can then check the values of the variables easily, to track down the error
        Message 3 of 7 , Dec 1, 2005
        • 0 Attachment
          Some questions so:

          1) did you run your code in the debugger step-by-step?
          you can then check the values of the variables easily,
          to track down the error

          2) can you discribe, in detail, how this routine should work?

          3) did you run the code I provided?
          you could then see if it works for you

          ---
          Stefan Pendl


          > -----Ursprüngliche Nachricht-----
          > Von: libertybasic@yahoogroups.com
          >
          >
          > Sorry I forgot to mention there is a password file I am accessing
          > seperately. Also, with the EOF loop, it's supposed to search through
          > my file. I've done it before with a search engine, I just can't
          > figure out why it won't work this time.






          ___________________________________________________________
          Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de
        Your message has been successfully submitted and would be delivered to recipients shortly.