Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please include the file Passwords.txt Write a program in C++ that checks passwor

ID: 3699093 • Letter: P

Question

Please include the file Passwords.txt Write a program in C++ that checks passwords input by the user. The program will continue to check passwords until the user inputs finish A strong password contains at least one capital letter, one lower case letter, one number, and one symbol, and a length at least 8. Additionally your program should store all the input passwords (except finish) into a file called passwords.txt Your program should run like this Welcome to the password verification progran Please input a password, the program will te A good password has at least one capital let one lowercase letter, a number and a special a length of at least 8 characters Password: password password is too weak Password: Password Password is too weak Password: Passi Pass1 is too weak Password: Passl Passi% is too weak Password: pAssW123 pAss123 is too weak Password: Pass!23% PasSI23% is a good password Password: finish Goodbye..

Explanation / Answer

Let me know if you have any doubts.

#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <cstring>
#include <iostream>
#include <fstream>

using namespace std;

// Function declarations
char* getInput(const int SIZE);
bool checkLength(char* password);
bool checkCase(char* password);
bool checkDigit(char* password);
bool checkSymbol(char* password);

                   int main()
                   {
                      
                           ofstream file;
                           file.open ("passwords.txt");
                   // Declaring variables
                   int size = 80, cnt;
                  const char* str = "finish";
                   char* ptrPassword;
                  
              

                   /* This loop continue to execute until
                   * the user enters a valid password
                   */
                  
                  
                   while (1)
                   {
                   cnt = 0;
                   // Calling the function to get the input
                   ptrPassword = getInput(size);
                    
                     
                    
                    
                      if(   strcmp(ptrPassword,str) == 0)            // here code is checked whteher enterd is finish
                        {
                        cout<< "GoodBye";
                       std::exit(0);  
               }
              
                 
                   file << ptrPassword<<" ";                        // password written to text file
              
              
                   // calling the function to check the length of password
                   bool blen = checkLength(ptrPassword);
                   // based on the return value display message
                   if (blen == false)
                   {
                   cout << "password is too weak" << endl;
                   cnt++;
                   }
                  
                   /* calling the function to check
                   * the upper case or lower case in the password
                   */
                   bool bcase = checkCase(ptrPassword);
                   // based on the return value display message
                   if (bcase == false)
                   {
                   cout << "password is too weak" << endl;
                   //cout << " password is too weak" << endl;
                   cnt++;
                   }
                   /* calling the function to check
                   * for the digit in the password
                   */
                   bool bdigit = checkDigit(ptrPassword);
                   // based on the return value display message
                   if (bdigit == false)
                   {
                   cout << "password is too weak" << endl;
                   cnt++;
                   }
                   // calling the function to check for the symbol in password
                   bool bsymbol = checkSymbol(ptrPassword);
                   // based on the return value display message
                   if (bsymbol == false)
                   {
                   cout << "password is too weak" << endl;
                   cnt++;
                   }
                  
                   /* if all the conditions satisfied the display success message
                   * if not,promt the user to enter password again
                   */
                   if (cnt == 0)
                   {
                   cout << " The password is good: " << ptrPassword << endl;
                   break;
                   }
                   else
                   continue;
                  
                   
                   }
                  
                   // file.close();

                   return 0;
                   }

// This function will get the input entered by the user
char* getInput(const int SIZE)
{
char* password;
password = new char[SIZE];
cout << " Enter Password :";
cin.getline(password, SIZE);

return password;
}

// this function will check for the valid length of the password
bool checkLength(char* password)
{
int length = strlen(password);
if (length >= 8 && length<=20)
return true;
else
return false;
}

/* this function will check whether pwd contains
* atleast one uppercase and lower case letter
*/
bool checkCase(char* password)
{
int ucnt = 0, lcnt = 0;
for (int i = 0; i < strlen(password); i++)
{
if (isupper(password[i]))
{
ucnt++;
}
if (islower(password[i]))
{
lcnt++;
}
}
if (ucnt >= 1 && lcnt >= 1)
return true;
else
return false;
}
/* This function will check whether the
* password contains atleast one digit or not
*/
bool checkDigit(char* password)
{
int digitcnt = 0;
for (int i = 0; i < strlen(password); i++)
{
if (isdigit(password[i]))
{
digitcnt++;
}
}
if (digitcnt >= 1)
return true;
else
return false;
}
// This function will check for the symbol in the password
bool checkSymbol(char* password)
{
int specialcnt = 0;
for (int i = 0; i < strlen(password); i++)
{
if (!isalpha(password[i]) && !isdigit(password[i]))
{
specialcnt++;
}
}
if (specialcnt >= 1)
return true;
else
return false;
}