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

Passwords, if weak, can be easy to guess or crack. That is why most secure syste

ID: 3749525 • Letter: P

Question

Passwords, if weak, can be easy to guess or crack. That is why most secure systems force users to choose passwords that are hard to guess. You are asked to write a password verifier that enforces the following rules: The password should be at least 8 characters long. The password should at least have one uppercase and one lowercase. The password should have at least one special character. The password should have at least one digit. The following requirements should be also implemented - Your program should allow the user to enter a password of any length'character list,and then verify that these eriteria are met. If password criteria are met, the program should indicate that the password is valid. Otherwise, it should tel the users what are ALL the rules that the chosen password fails to adhere to. length/character list, and then verify that these criteria are met In case the entered password is wrong, the program should not exit, but rather give the user the chance to enter a new password to be verified.

Explanation / Answer

isupper() and islower() and their application in C++

In C++, isupper() and islower() are predefined functions used for string and character handling.cstring.h is the header file required for string functions and cctype.h is the headerfile required for character functions.

isupper() Function
This function is used to check if the arguement contains any uppercase letters such as A, B, C, D……….Z.

// Program to check if a character is in

// uppercase using islower()

#include <iostream>

#include <cctype>

using namespace std;

int main()

{

    char x;

    cin >> x;

    if (isupper(x))

        cout << "Uppercase";

    else

        cout << "Not uppercase.";   

    return 0;

}

islower() Function
This function is used to check if the arguement contains lowercase letters such as a, b, c, d, ……..z.

// Program to check if a character is in

// lowercase using islower()

#include <iostream>

#include <cctype>

using namespace std;

int main()

{

    char x;

    cin >> x;

    if (islower(x))

        cout << "Lowercase";

    else

        cout << "Not Lowercase.";   

    return 0;

}

Application of islower(), isupper(), tolower(), toupper() function.
Given a string, task is to convert the characters in the string into opposite case, i.e. if a character is in lowercase, we need to convert it into uppercade and vice versa.

Examples:

1. Traverse the given string character by character upto its length, check if character is in lowercase or uppercase using predefined function.
3. If lowercase, convert it to uppercase using toupper() function, if uppercase, convert it to lowercase using tolower() function.
4. Print the final string.

// C++ program to toggle cases of a given

// string.

#include <iostream>

#include <cstring>

using namespace std;

// function to toggle cases of a string

void toggle(string& str)

{

    int length = str.length();

    for (int i = 0; i < length; i++) {

        int c = str[i];

        if (islower(c))

            str[i] = toupper(c);

        else if (isupper(c))

            str[i] = tolower(c);       

    }

}

// Driver Code

int main()

{

    string str = "GeekS";

    toggle(str);

    cout << str;

    return 0;

}

// Program to check if a character is in

// uppercase using islower()

#include <iostream>

#include <cctype>

using namespace std;

int main()

{

    char x;

    cin >> x;

    if (isupper(x))

        cout << "Uppercase";

    else

        cout << "Not uppercase.";   

    return 0;

}

islower() Function
This function is used to check if the arguement contains lowercase letters such as a, b, c, d, ……..z.

  Syntax  int islower(int x)  

// Program to check if a character is in

// lowercase using islower()

#include <iostream>

#include <cctype>

using namespace std;

int main()

{

    char x;

    cin >> x;

    if (islower(x))

        cout << "Lowercase";

    else

        cout << "Not Lowercase.";   

    return 0;

}

Application of islower(), isupper(), tolower(), toupper() function.
Given a string, task is to convert the characters in the string into opposite case, i.e. if a character is in lowercase, we need to convert it into uppercade and vice versa.

Examples:

  Input : GeekS  Output :gEEKs    Input :Test Case  Output :tEST cASE  

1. Traverse the given string character by character upto its length, check if character is in lowercase or uppercase using predefined function.
3. If lowercase, convert it to uppercase using toupper() function, if uppercase, convert it to lowercase using tolower() function.
4. Print the final string.

// C++ program to toggle cases of a given

// string.

#include <iostream>

#include <cstring>

using namespace std;

// function to toggle cases of a string

void toggle(string& str)

{

    int length = str.length();

    for (int i = 0; i < length; i++) {

        int c = str[i];

        if (islower(c))

            str[i] = toupper(c);

        else if (isupper(c))

            str[i] = tolower(c);       

    }

}

// Driver Code

int main()

{

    string str = "GeekS";

    toggle(str);

    cout << str;

    return 0;

}