| | |
Hi to all, I am a newbi
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2007
Posts: 2
Reputation:
Solved Threads: 0
Hi, I am supose to do a program in C++ that tests for a password
it should do the following:
a- the password should be between 6 and nine characters
b- the password should contain at least one upper case and at least one lowercase letter
c- the password should contain at least one digit
the program works fine to check for requirements b and c but it does not work properly when I check the string length here is the code I got so far:
Thanks is advance
it should do the following:
a- the password should be between 6 and nine characters
b- the password should contain at least one upper case and at least one lowercase letter
c- the password should contain at least one digit
the program works fine to check for requirements b and c but it does not work properly when I check the string length here is the code I got so far:
Thanks is advance

c++ Syntax (Toggle Plain Text)
#include <iostream> #include <cctype> #include <cstring> using namespace std; bool testlower( char [], int); bool testupper( char[], int); bool testdigit( char[],int); bool testnum(char[]); int main() { int const size = 10; //can handle 9 characters char password[size]; cout <<" Enter your password:" <<endl; cout <<" Make sure that its more than six characters\n"; cout <<" and its less than 9 characters long.\n"; cout <<" has at least one digit and \n"; cout <<" at least one uppercase and lower case letter\n"; cout <<" otherwise the program wont work proberly, thank you for you cooporation\n"; cin.getline(password,size); if ((testlower( password, size) && testupper (password,size) && testdigit ( password,size)&& testnum(password))== true) cout <<"the password that you entered is valid\n"; if ( testlower( password,size) == false ) { cout<<" the password that you entered is invalid because there is\n"; cout<<" no lower case letter in your password.\n"; } if( testupper( password, size) == false) { cout<<" the password that you entered is invalid because there is\n"; cout<<" no upper case letter in your password.\n"; } if ( testdigit(password,size) == false) { cout<<" the password that you enterd is invalid because there is\n"; cout<<" not digits in your password\n"; } if (testnum(password)== false) { cout<<" the password that you entered is invalid because the number\n"; cout<<" of characters is less than 6 or is more than 9 \n"; } return 0; } //------------------------------------------------------- bool testlower(char password[], int size) { for ( int count=0; count < (size-1); count++) { if( islower(password[count])) return true; } return false; } //-------------------------------------------------------- bool testupper( char password[], int size) { for ( int count=0; count < (size-1); count++) { if ( isupper( password[count])) return true; } return false; } //------------------------------------------------------- bool testdigit( char password[], int size) { for ( int count=0; count < (size-1); count++) { if ( isdigit(password[count])) return true; } return false; } //this is where the code in not working properly I tried to modify it in many ways //but still can't get the right asnwer bool testnum( char password[]) { int length; length = strlen(password); if( length < 6 || length <=9) { return false; } return true; }
Last edited by Ancient Dragon; Nov 20th, 2007 at 9:15 pm. Reason: add code tags
>>but it does not work properly when I check the string length
Just add code to call strlen() to get the password length the check if it is <= 9. If you really wrote all that code you posted you should have no problem checking for length.
Just add code to call strlen() to get the password length the check if it is <= 9. If you really wrote all that code you posted you should have no problem checking for length.
Last edited by Ancient Dragon; Nov 20th, 2007 at 9:19 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Another thing to consider, what if the user enters 15 characters? All you read are the first 9 and he thinks his password is longer than it is. You should probably accept more characters and give an error if 10 or more are entered.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
- Newbi can anyone help with methods and classes (Java)
- rundll32.exe problems (Windows NT / 2000 / XP)
- URL's (Links) in MSN.com "Hotmail" do not work. (Web Browsers)
- Explorer Caused An Invalid Page Fault (Windows 95 / 98 / Me)
Other Threads in the C++ Forum
- Previous Thread: RougeWave CTLib help
- Next Thread: "breaking up" your application
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg simple sorting string strings temperature template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






