Thread: Simple login/password check

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    14
    Hi Lithorien

    Well you can guess what we are using at University can't you? Yep MS Visual C++ V 6.0. They have to use a standardised OS and software and this is what we use. It as consequence is the only IDE that I have used. I have just built a Linux machine to use with my Amateur Radio hobby and I intend to carry on learning C++ and do most of my programming on that machine. So I'll be back looking for advice on complilers after my exams on the 28th.

    Meanwhile thanks for the help, incidently running login.exe from a command prompt produces the same result so I presume the MS debugger takes over the whole machine!

    ceevee

  2. #17
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Hm. It's double-enter even from a command prompt? Odd.

    I'll work with it.

  3. #18
    Registered User
    Join Date
    Jan 2005
    Posts
    14
    Yes I even tried the exe file on an older machine and I get the same results. I can't for the life of me figure out why. I am also trying to change it so that it runs again as soon as an incorrect user name is entered. As it is now it asks for a password even if the user name is incorrect.

    I know that the tutors will try to break this. I have just spoken to a few of my class mates all of whom have failed to get this project even close to finished. I think that the teaching is at fault here, not us!

    ceevee

  4. #19
    Registered User
    Join Date
    Jan 2005
    Posts
    14
    Well I fixed it like this:
    Code:
    while (goodup != 1) 
    
       { 
           cout << "\n\n\tPlease enter your username (first [space] last): "; 
    	   cin >> firstName >> lastName; 
           UserName = firstName+" "+lastName;
    	   
        
           cout << "\n\tPlease enter your password: "; 
           cin >> Password; 
                    
           ScanFile(UserName, Password); 
       }
    taking out the getline seems to have done the trick. As all the passwords are in the form xxx xxx it doesn't cause me any limitations. I don't understand why this has cured it though, I thought that getline read until it encounterd a null character.

    The password input only requires one enter now as well without further modification. Strange!

    Thanks very much for all of your help.

    ceevee

  5. #20
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I'm rather surprised at this thread, for two reasons.
    1) People are handing out completed code with no comments, explanation, etc.. It seems ceevee is being good about it and actually going through it to figure out how it works rather than just copy/paste/hand-in, which I'm glad about - But code handouts are highly frowned upon here, because most of the time people just take it and hand it in, which is of course cheating.

    2) The thread hasn't been closed on account of reason #1.

    Ceevee, I hope I wasn't wrong about you going through the code to learn how it functions. In any case, the problem with having to hit [enter] twice is simply a bug in Microsoft Visual C++ 6.0. Newer versions of the compiler (see this thread, last post) are free for download, and don't have the problem. Otherwise, you can fix the bug manually by following the instructions at this site, under the "Fix to <istream>" section:
    http://www.dinkumware.com/vc_fixes.html
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #21
    Registered User
    Join Date
    Jan 2005
    Posts
    14
    Hi Kevin.

    I agree with what you say and no I am not just copying and handing it in. I am however, very grateful for the help that I have received on here. The original code that appeared on this thread was written by me as were the other 15 or so functions that will be included in this assignment when I hand it in tomorrow. I see little point in cheating at my age

    I work in R&D as an RF designer (part time until I finish the degree) for a large company and I have no compunction when asking people about topics that I cannot figure out for myself. I always try to figure things out first. Neither I (nor anyone else) would last a day at work were I to claim an ability that I do not have.

    Basically my classmates and I have been the victim of an ill conceived course with very poor tuition. I attended the lectures and I have still found myself learning C++ from scratch from books and websites in the last three weeks. This code is incorporated as a module into my program and has been altered substantially to suit my needs.

    On the upside I now have the beginnings of an interest in the subject and will continue to study the language for my own satisfaction.

    Once again I'd like to thank everyone for their time, generosity and help.

    ceevee.

  7. #22
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Yes, I noticed that your code was very nearly complete as it was, and I didn't realize how minor the changes Hermitsky made to it were. On the other hand, the first few code suggestions were untested and poorly thought out (eh? You want it to loop? Stick it in a while(1) block. What's that? It doesn't quit properly? I'll put it in a function and slap on a return statement. Gee, still not working. Let's add in.close(), even though that happens already anyway. Let me know if it fixes everything.).

    A proper solution would have been to, instead of putting everything in an infinite loop, put it in a loop with a sentinel variable called 'ok' or 'done' for example, which gets set when the correct username and password are entered.

    The problem with the first code suggestion is that break; only jumps out of the innermost loop, in this case the while(!in.eof()) loop, and the while(1) loop keeps going forever. In the second, while it fixes the first problem, it's usually bad practice to make major changes to your program just so you can use return as a 'break' mechanism (though there is nothing wrong with using return in that way), when another simpler solution would suffice just as well. The third attempt was just a 'throw something out and hope it works' solution. The REAL problem was not that the file isn't closed; it's that end-of-file is reached, setting an error flag in the ifstream, which means that any subsequent attempts to open a file or read from one will result in failure. To correct this, you simply add a call to in.clear() before in.open(), to clear the EOF error flag. If Hermitsky had simply tested his programs before posting them, all of this could have been condensed into a single code posting that worked.

    I haven't read through Lithorien's solution, but I'll assume that it was more thoughtfully composed since at least it worked - as I mentioned earlier, the 'hit enter twice' bug in Lithorien's code was through no fault on the part of the programmer. I hope you do apply the getline() fix, because there is really no substitute for its usefulness. Unless, of course, the people testing your program will have bugged compilers too, and though the program works properly on your own computer they will have problems
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #23
    Registered User
    Join Date
    Jan 2005
    Posts
    14
    Hi Hunter.

    I am not sure but I suspect that they will be using the same compiler as me. Their theory is likely to be that if it works for us using MS Visual C++ V6 it should work for them. I have decided to make a large note of the problem and email the lecturer to as well as offer a complete exe that has been compiled properly. At least that shows that I understand the problem. In the email I'll point the lecturer to the thread that you posted.

    So it's finished and I'm just clearly commenting and formatting the code as we speak. I have to finish of the written part of the assignment and hope that my hopelessly amateurish pseudo code is acceptable. I have done a data flow chart which is clear anyway.

    From what I gather I am the only person who will be handing in a complete and functional program tomorrow.

    Most are moaning about the lecturer which is a fair point but it won't get them a pass mark. I decided to just get on with it!

    Thanks for your clear and concise explanation of why the code wasn't working. I have used getline extensively to read in data from the three account files that were provided with the assignment.

    Thanks again.

    ceevee

  9. #24
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Quote Originally Posted by Hunter2
    I haven't read through Lithorien's solution, but I'll assume that it was more thoughtfully composed since at least it worked - as I mentioned earlier, the 'hit enter twice' bug in Lithorien's code was through no fault on the part of the programmer. I hope you do apply the getline() fix, because there is really no substitute for its usefulness. Unless, of course, the people testing your program will have bugged compilers too, and though the program works properly on your own computer they will have problems
    To answer your complaint about full code: I wrote the entire code out without comments because this fellow seemed like he knew what he was doing and talking about. And instead of taking his code and re-writing it (I didn't really like the inital setup, different coding style), I just wrote new code that might have illustrated some points for him to use in his own, or to impliment fully. Didn't mean to break any etiquette.

    To answer your quoted paragraph: I never post code anywhere that I have not tested for functionality. I hate finding threads with broken code, and I refuse to do it myself unless I absolutely have to in order to prove a point.

  10. #25
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    Quote Originally Posted by Lithorien
    I hate finding threads with broken code...
    That to me is like a Christmas present! Broken says to me: "Fix me Kleid! Fix me up and make me better so I can run on your machine!" And I'm like: "You got it!". Then at the end I get experience points and I'm level 4! People think differently, that's all

  11. #26
    Registered User
    Join Date
    Jan 2005
    Posts
    14
    Well it's 05:17 here in the UK and I'm still writing this thing up. It works well, I can't break it and I'm feeling quite proud of myself. FWIW Lithorian I will be eternally grateful to you, I was getting a little upset about that particular thing. I did learn from it, you helped me, surely that's what it's all about. I am sorry if I have caused any problems for anyone.

    ceevee

  12. #27
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    Quote Originally Posted by Hunter2
    If Hermitsky had simply tested his programs before posting them, all of this could have been condensed into a single code posting that worked.
    We've got to think optimistically here, to survive cyberspace! You see, it's good that Hermitsky kept screwing up, because that forces us to think more. It improves our thinking capacity , thus everyone at CProgramming.com gets x10 smarter! I can see Ceevee becoming a C programming fiend! Hermitsky has the meat, Ceevee gets the experience, and it all works out.
    Last edited by Kleid-0; 01-17-2005 at 12:07 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. allegro issues
    By mramazing in forum C++ Programming
    Replies: 1
    Last Post: 01-07-2009, 11:56 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Simple check program
    By Shadow in forum C Programming
    Replies: 3
    Last Post: 06-05-2002, 06:20 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 12:51 AM