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...
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.
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.
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...
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...
Developer User Account Create a user account using T-SQL for developers named DEVELOPER with the password...
Developer User Account Create a user account using T-SQL for developers named DEVELOPER with the password TESTACCOUNT that grants the user the ability to: Select and modify any table. Connect to and have access to all resources. In SSMS
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
Instructions: In this exercise, you’ll design a role playing character class. The Character class attributes should...
Instructions: In this exercise, you’ll design a role playing character class. The Character class attributes should include the characters’s name, gender, class* and race (can be human, elf or dwarf), and additional integer attributes of Strength, Dexterity, Constitution, Intelligence, Wisdom, Charisma. Your class should have a constructor that receives this data. For each attribute, provide setters and getters. The class should include methods that calculate and return the user’s total attributes (sums 6 attributes). Write a Java application that prompts...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT