Hi to all, I am a newbi

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 2
Reputation: DamiLeon is an unknown quantity at this point 
Solved Threads: 0
DamiLeon DamiLeon is offline Offline
Newbie Poster

Hi to all, I am a newbi

 
0
  #1
Nov 20th, 2007
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
  1. #include <iostream>
  2. #include <cctype>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. bool testlower( char [], int);
  8. bool testupper( char[], int);
  9. bool testdigit( char[],int);
  10. bool testnum(char[]);
  11.  
  12.  
  13.  
  14. int main()
  15. {
  16. int const size = 10; //can handle 9 characters
  17. char password[size];
  18.  
  19.  
  20. cout <<" Enter your password:" <<endl;
  21. cout <<" Make sure that its more than six characters\n";
  22. cout <<" and its less than 9 characters long.\n";
  23. cout <<" has at least one digit and \n";
  24. cout <<" at least one uppercase and lower case letter\n";
  25. cout <<" otherwise the program wont work proberly, thank you for you cooporation\n";
  26. cin.getline(password,size);
  27.  
  28.  
  29. if ((testlower( password, size) && testupper (password,size) && testdigit ( password,size)&& testnum(password))== true)
  30. cout <<"the password that you entered is valid\n";
  31.  
  32.  
  33. if ( testlower( password,size) == false )
  34. {
  35. cout<<" the password that you entered is invalid because there is\n";
  36. cout<<" no lower case letter in your password.\n";
  37. }
  38. if( testupper( password, size) == false)
  39. {
  40. cout<<" the password that you entered is invalid because there is\n";
  41. cout<<" no upper case letter in your password.\n";
  42. }
  43. if ( testdigit(password,size) == false)
  44. {
  45. cout<<" the password that you enterd is invalid because there is\n";
  46. cout<<" not digits in your password\n";
  47. }
  48. if (testnum(password)== false)
  49. {
  50. cout<<" the password that you entered is invalid because the number\n";
  51. cout<<" of characters is less than 6 or is more than 9 \n";
  52. }
  53.  
  54. return 0;
  55.  
  56.  
  57. }
  58. //-------------------------------------------------------
  59.  
  60. bool testlower(char password[], int size)
  61. {
  62. for ( int count=0; count < (size-1); count++)
  63. {
  64. if( islower(password[count]))
  65.  
  66. return true;
  67.  
  68.  
  69. }
  70. return false;
  71. }
  72. //--------------------------------------------------------
  73.  
  74. bool testupper( char password[], int size)
  75. {
  76. for ( int count=0; count < (size-1); count++)
  77. {
  78. if ( isupper( password[count]))
  79.  
  80. return true;
  81.  
  82.  
  83. }
  84. return false;
  85. }
  86. //-------------------------------------------------------
  87. bool testdigit( char password[], int size)
  88. {
  89. for ( int count=0; count < (size-1); count++)
  90. {
  91. if ( isdigit(password[count]))
  92.  
  93. return true;
  94.  
  95.  
  96. }
  97.  
  98. return false;
  99. }
  100. //this is where the code in not working properly I tried to modify it in many ways
  101. //but still can't get the right asnwer
  102.  
  103. bool testnum( char password[])
  104. {
  105. int length;
  106. length = strlen(password);
  107.  
  108. if( length < 6 || length <=9)
  109. {
  110. return false;
  111. }
  112.  
  113. return true;
  114. }
Last edited by Ancient Dragon; Nov 20th, 2007 at 9:15 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,472
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1477
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Hi to all, I am a newbi

 
0
  #2
Nov 20th, 2007
>>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.
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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Hi to all, I am a newbi

 
0
  #3
Nov 20th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3
Reputation: wambooman is an unknown quantity at this point 
Solved Threads: 0
wambooman wambooman is offline Offline
Newbie Poster

Re: Hi to all, I am a newbi

 
0
  #4
Nov 21st, 2007
length < 6
I read length smaller than 6. I don't think you want that
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC