Question

In: Computer Science

Class Instructions You will create a password verification program using C-strings and character testing. The user...

Class Instructions

You will create a password verification program using C-strings and character testing.

The user will enter a password as a C-string. (Character array). You must test that the password contains at least:

  • One lowercase letter
  • One uppercase letter
  • One number (0-9)
  • The password can contain no spaces
  • You are to add one more requirement to the password.

I need help in setting this program up.

#include <iostream>

#include <cctype>

using namespace std;

int main() {

char input;

cout << "Enter any character: ";

cin.get(input);

cout << "The character you entered is: " << input << endl;

if (isalpha(input))

cout << "That's an alphabetic character.\n";

if (isdigit(input))

cout << "That's a numeric digit.\n";

if (islower(input))

cout << "The letter you entered is lowercase.\n";

if (isupper(input))

cout << "The letter you entered is uppercase.\n";

if (isspace(input))

cout << "That's a whitespace character.\n";

return 0;

}

Solutions

Expert Solution

#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
enum PWSIZE //Array Size
{
    PASSWORD_SIZE = 20
};
//Function Prototype
int testNum(char []);
int main()
{
    char password[PASSWORD_SIZE]; //To hold password
    int length;
        int flag=0;
    length = strlen(password);
    cout<< "Please enter a password with at least 6 characters.\n";
    while(1)
    {
        //Get the password.
        do{
                
                        if(flag==0)
                cout << "Enter your password: ";
            else
                cout << "Re-enter your password: ";
            cin.getline(password, PASSWORD_SIZE);
            length = strlen(password);
        }while(length < 6);

        //Call function.
        if(testNum(password))
        {
           cout<<"The entered password is correect pattern.\n" ;
           break;
                }          //if return 1 pass below
        else
        {
                    flag=1;
            continue;
            }
    }
    return 0;
}

int testNum(char pswd[])
{
    int count;
    bool upper_flag = 0, lower_flag = 0, digit_flag = 0,space_flag=1,spcchar_flag=0;
    for (count = 0; count<strlen(pswd); count++)    //don't need to Size use strlen
    {

        if (isupper(pswd[count]))
            upper_flag = 1;
        else if (islower(pswd[count]))
            lower_flag = 1;
        else if (isdigit(pswd[count]))
            digit_flag = 1;
        else if (isspace(pswd[count]))
                space_flag=0;
        else
                spcchar_flag=1;
    }
    if(!upper_flag)
    {
        cout << "The password does not contain an uppercase letter.\n";
    }
    if(!lower_flag)
    {
        cout << "The password does not contain a lowercase letter.\n";
    }
    if(!digit_flag)
    {
        cout << "The password does not contain a digit.\n";
    }
    if(!space_flag)
    {
        cout << "The password does  contain a space.\n";
    }
        if(!spcchar_flag)
    {
        cout << "The password does not contain a special character(like @,%,$,# etc).\n";
    }
    if(upper_flag && lower_flag && digit_flag && space_flag && spcchar_flag)
        return 1;   //if all pass
    else
        return 0;
}

OUTPUT:-

Please enter a password with at least 6 characters.
Enter your password: sdas@1997
The password does not contain an uppercase letter.
Re-enter your password: sdas 1@997
The password does not contain an uppercase letter.
The password does contain a space.
Re-enter your password: Sdas@1997
The entered password is correect pattern.


Related Solutions

Using C++ Write a program to ask user to enter a password and validity the password....
Using C++ Write a program to ask user to enter a password and validity the password. The password should be 8 – 20 characters long (8 is included and 20 is included), it should contain at least one uppercase letter and one lower case letter. The password should contain at least one digit, and at least one symbol other than alphabets or numbers. Most importantly, the password may not contain any white space. Functions: You will need at least the...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will first enter a password, then enters the same password again; If the second input is the same as first one, the user successfully creates the password. Print “Well done.”; Otherwise, the user will be directed to repeat the whole process (go to step 1.)
Write C++ code that prompts the user for a username and password (strings), and it calls...
Write C++ code that prompts the user for a username and password (strings), and it calls the login() function with the username and password as arguments. You may assume that username and password have been declared elsewhere. Your code should print error messages if login() generates an exception: LoginException: "Username not found or password incorrect" ServerException: "The login server is busy and you cannot log in" AccessException: "Your account is forbidden from logging into this server" Any other exception: "Unknown...
Write C++ code that prompts the user for a username and password (strings), and it calls...
Write C++ code that prompts the user for a username and password (strings), and it calls the login() function with the username and password as arguments. You may assume that username and password have been declared elsewhere. Use virtual functions, pure virtual functions, templates, and exceptions wherever possible. Please explain the code. Your code should print error messages if login() generates an exception: LoginException: "Username not found or password incorrect" ServerException: "The login server is busy and you cannot log...
C# Create an application that asks the user to enter their new password. The password must...
C# Create an application that asks the user to enter their new password. The password must be at least 6 characters long. Develop a custom exception handling case that checks for the password length. (hint: use " .Length " built-in method). If the new password is less than 6 characters long the custom exception should output an error message.
c++ Develop a program that validates a password entered by a user. The password must meet...
c++ Develop a program that validates a password entered by a user. The password must meet the following criteria: Be at least six characters long. Contain at least one uppercase and at least one lowercase letter. Have at least one digit. Write a program that asks for a password and then verifies that it meets the stated criteria. If it does not, the program should display a message telling the user why and ask for another password. The program should...
Code a program which asks user to enter two strings using Scanner class and returns the...
Code a program which asks user to enter two strings using Scanner class and returns the total number of non-space characters in the Strings. For ex: “Hi there” and “hello” should return 12.
A password verification system that does not allow user passwords to be proper names or words...
A password verification system that does not allow user passwords to be proper names or words that are normally included in a dictionary is an example of ___________ with respect to security systems. Group of answer choices Attack Risk Asset Countermeasure
Create a c++ program that: Create an input file using notepad ( .txt ). When testing...
Create a c++ program that: Create an input file using notepad ( .txt ). When testing your program using different input files, you must change the filename inside your program otherwise there will be syntax errors. There are a finite number of lines to be read from the data file. But we can’t assume to know how many before the program executes; so, the standard tactic is to keep reading until you find the “End of File” marker. Input date...
Using C++ Create a program that asks the user to input a string value and then...
Using C++ Create a program that asks the user to input a string value and then outputs the string in the Pig Latin form. - If the string begins with a vowel, add the string "-way" at the end of the string. For “eye”, it will be “eye-way”. - If the string does not begin with a vowel, first add "-" at the end of the string. Then rotate the string one character at a time; that is, move the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT