fork download
  1. //Saliha Babar CS1A Chapter 10, #12, Page 590
  2. //
  3. /****************************************************************************
  4.  * VERIFY PASSWORD
  5.  * ___________________________________________________________________________
  6.  * This program accepts string and determines whether that string meet certain
  7.  * password requirements.
  8.  *
  9.  * The requirements include
  10.  * at least 6 characters, at least one upper case & one lowercase & one digit
  11.  * ____________________________________________________________________________
  12.  * INPUT
  13.  * SIZE : maximum size of password
  14.  * password : array of characters
  15.  *
  16.  * OUTPUT
  17.  * lengthCheck : check for string length
  18.  * upperCheck : check for uppercase letter
  19.  * lowerCheck : check for lowercase letter
  20.  * digitCheck : check for digits
  21.  * **************************************************************************/
  22. #include <iostream>
  23. #include <cstring>
  24. #include <cctype>
  25. using namespace std;
  26.  
  27. bool CheckLength(char array[], int SIZE);
  28. bool CheckUpper (char array[], int SIZE);
  29. bool CheckLower (char array[], int SIZE);
  30. bool CheckDigit (char array[], int SIZE);
  31.  
  32.  
  33. int main() {
  34. const int SIZE = 15; // INPUT - maximum size of string
  35. char password[SIZE]; // INPUT - array to hold characters
  36. bool tryAgain = true ; // Check for overall criteria
  37. bool lengthCheck; // Check for string length
  38. bool upperCheck; // Check for uppercase letter
  39. bool lowerCheck; // Check for lowercase letter
  40. bool digitCheck; // Check for digits
  41.  
  42. cout << "Enter a password up to " <<SIZE-1<< " characters that includes\n";
  43. cout << "at least 6 characters\n";
  44. cout << "at least one uppercase and one lowercase\n";
  45. cout << "at least one digit\n";
  46.  
  47. while (tryAgain)
  48. {
  49. cout << "Enter the password as you wish.\n";
  50. cin.getline (password, SIZE);
  51. lengthCheck = CheckLength (password, SIZE);
  52. upperCheck = CheckUpper (password, SIZE);
  53. lowerCheck = CheckLower (password, SIZE);
  54. digitCheck = CheckDigit (password, SIZE);
  55.  
  56. tryAgain = lengthCheck || upperCheck || lowerCheck || digitCheck;
  57. }
  58.  
  59. cout << "Your password meets the criteria & verified..\n";
  60.  
  61. return 0;
  62. }
  63.  
  64. bool CheckLength(char array[],int SIZE)
  65. {
  66. if (strlen(array) < 6)
  67. {
  68. cout << "You did not entered password with at least 6 characters.\n";
  69. return true;
  70. }
  71.  
  72. else
  73. return false;
  74. }
  75.  
  76. bool CheckUpper (char array[], int SIZE)
  77. {
  78. for (int i = 0; i < SIZE ; i++)
  79. {
  80. if (isupper(array[i]))
  81. return false;
  82. }
  83.  
  84. cout << "Your password doesnt contain at least one UpperCase letter\n";
  85. return true;
  86. }
  87.  
  88.  
  89. bool CheckLower (char array[], int SIZE)
  90. {
  91. for (int i = 0; i < SIZE ; i++)
  92. {
  93. if (islower(array[i]))
  94. return false;
  95. }
  96.  
  97. cout << "Your password doesnt contain at least one lowercase letter\n";
  98. return true;
  99. }
  100.  
  101. bool CheckDigit (char array[], int SIZE)
  102. {
  103. for (int i = 0; i < SIZE ; i++)
  104. {
  105. if (isdigit(array[i]))
  106. return false;
  107. }
  108.  
  109. cout << "Your password doesnt contain at least one digit\n";
  110. return true;
  111. }
Success #stdin #stdout 0s 5284KB
stdin
Sal23
SalihaBabar09
stdout
Enter a password up to 14 characters that includes
at least 6 characters
at least one uppercase and one lowercase
at least one digit
Enter the password as you wish.
You did not entered password with at least 6 characters.
Enter the password as you wish.
Your password meets the criteria & verified..