Quick Question

This is a discussion on Quick Question within the C++ Programming forums, part of the General Programming Boards category; Hi. I have written a simple password system which lets a supervisor input 10 passwords, and then a user can ...

  1. #1
    Much older and wiser Fountain's Avatar
    Join Date
    Dec 2001
    Location
    Engeeeerland
    Posts
    1,158

    Question Quick Question

    Hi. I have written a simple password system which lets a supervisor input 10 passwords, and then a user can attempt to log on. The password is checked for length (via strlen). It is checked for<255 chars initially and then to ensure it is 6 chars long. Strcmp and return val then check for a match when a user attempts an input. I have also included a 3 guess system which terminates the program if the user fails to log on within 3 tries.

    Finally i need to ensure the supervisors and users passwords are inputted in the format of two letters and four numbers.

    Any ideas on the best (or only) way to do this? Currently I am using two dimensional arrays for the Password variable.

    A few ideas i.e ascii code checks or whatever would be appreciated.

    Many thanks..
    Such is life.

  2. #2
    Unregistered
    Guest
    evaluate each char in a password with a loop. Within the loop are two if statements. The first evaluates for digits with isdigit(). If any char is a digit, then a counter is incremented. The second if statememt evaluates for alphabetical letters (English only I think) with isalpha(). If the char is a letter then it increments a counter. Once the loop is completed evaluate the counters.

  3. #3
    Much older and wiser Fountain's Avatar
    Join Date
    Dec 2001
    Location
    Engeeeerland
    Posts
    1,158
    Thanks, but problem is I havent (supposedley) been shown how to use those functions yet! Is there another, more basic method???
    Such is life.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    129
    For small strings like yours this is probably the simpliest way - if you feel like having password more than those 6 characters (and having more digits than two in the beginning) another loop for numbers might be worthy.

    #include <ctype.h>
    .
    .
    .
    char passwd[7];
    // what ever you do to get the password
    if((isalpha(passwd[0]) == 0) || (isalpha(passwd[1] == 0))
    // Checks if first two ones are NOT letters
    // Place your error code here
    for(int i = 2; i < 7; i++)
    if(isdigit(passwd[i]) == 0)
    // Check those numbers (another error code here)
    kooma - t.h@iki.fi

  5. #5
    Registered User JTtheCPPgod's Avatar
    Join Date
    Dec 2001
    Posts
    44
    Well, theres no more simple or basic way to do it, but if you cant use those functions, heres an idea:
    Do something like a for loop to see if the ascii code of the character entered is either a letter or a number and have 6 ints (one for each character) and have the int for that character equal 0 if its not a valid char (like a symbol or something), 1 for a letter, and 2 for a number. If they enter the non valid char, just end the program or break the loop. Add up these ints at the end and if it equals 8 (1+1+1+1+2+2) (and make sure none are 0's, that's partly why you broke the loop earlier, or you could just put that in the if statement) then accept it.

  6. #6
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Go through, check the ASCII number of each one. If it checks our as a number, increment a tally. If it is a character, increment another one. Then just chekc 'em at the end.

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    11

    reply

    you can use getpass function in your program.Its very easy you donot ned to use array.You can explore ad tell me the result. I had also used it.
    All is well that ends well

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-27-2005, 12:05 AM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 04:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 05:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 12:04 PM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 06:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21