Question

In: Computer Science

-Write in C++ -Use Char library functions Write a function that accepts a string representing password...

-Write in C++

-Use Char library functions

Write a function that accepts a string representing password and determines whether the string is a valid password. A valid password as the following properties:

1. At least 8 characters long

2. Has at least one upper case letter

3. Has at least one lower case letter

4. Has at least one digit

5. Has at least on special character

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

#include <iostream>
#include <cctype>
#include <string>
using namespace std;
// function declarations
bool isValidPassword(string password);
int main()
{
// Declaring variables
string password;
int cnt;
/* This while loop continues to execute
* until the user enters a valid password
*/
while (true)
{
cnt = 0;
// Getting the input entered by the user
cout << "\nEnter password :";
cin >> password;
// calling the function
bool b = isValidPassword(password);
if (b)
{
cout << "Valid Password" << endl;
break;
}
else
{
cout << "Invalid Password" << endl;
}
}
return 0;
}

bool isValidPassword(string password)
{
int flag = 0, cnt = 0;

if (password.length() < 8)
{
cout << "Length of the password must be atleast 8" << endl;
cnt++;
}
/* This function check whether the password
* contains atleast 1 lowercase character or not
*/
for (int i = 0; i < password.length(); i++)
{
if (isupper(password[i]))
{
flag = 1;
}
}
if (flag == 0)
{
cnt++;
cout << "Password contains atleast 1 lowercase character" << endl;
}

flag = 0;
/* Checking whether the password
* contains atleast 1 uppercase character or not
*/
for (int i = 0; i < password.length(); i++)
{
if (isupper(password[i]))
{
flag = 1;
}
}
if (flag == 0)
{
cnt++;
cout << "Password contains atleast 1 uppercase character" << endl;
}
flag = 0;

/* checking whether the password
* contains atleast 1 digit or not
*/
for (int i = 0; i < password.length(); i++)
{
if (isdigit(password[i]))
{
flag = 1;
}
}
if (flag == 0)
{
cnt++;
cout << "Password contains atleast 1 digit" << endl;
}

flag = 0;
/* checking whether the password
* contains atleast 1 special character or not
*/
for (int i = 0; i < password.length(); i++)
{
if ((password[i] == '!') || (password[i] == '@') || (password[i] == '#')
|| (password[i] == '$'))
{
flag = 1;
}
}
if (flag == 0)
{
cnt++;
cout << "Password must contain atleast one special character" << endl;
}

if (cnt == 0)
return true;
else
return false;
}

=======================================

=========================================

Output:

=====================Could you plz rate me well.Thank You


Related Solutions

There is a C function decodeMorse(const String & string, char message[]). This function examines the binary...
There is a C function decodeMorse(const String & string, char message[]). This function examines the binary string and iteratively constructs a decimal value (val) and width of each binary pattern (separated by spaces), until a space or a null character ('\0') is encountered in the string. Once a space or a null character is found, this function should call the assembly code (decode_morse()) to obtain the corresponding ASCII value, for the current val and width, and place the ASCII value...
[ Write in C, not C++] Define a function char* deleteSymbol(char *s, char x) that removes...
[ Write in C, not C++] Define a function char* deleteSymbol(char *s, char x) that removes the character x from string s. For s[] = “America”, a call to deleteSymbol(s, ‘a’) converts s[] = “Ame”
Write a recursive Racket function "remove-char" that takes two string parameters, s and c, and evaluates...
Write a recursive Racket function "remove-char" that takes two string parameters, s and c, and evaluates to string s with all occurrences of c removed. The string c is guaranteed to be a length-1 string; in other words a single character string. For example (remove-char "abc" "b") should evaluate to "ac". Here is pseudocode that you could implement.
Write a python function to fulfill the requirements. The function accepts a string, a current state,...
Write a python function to fulfill the requirements. The function accepts a string, a current state, edges’ information, and an accepting state. The output of the function is a boolean value verifying if the string can pass the finite state machine or not.             ### Finite State Machine Simulator in Python ### Provide s1 and s2 that are both accepted, but s1 != s2. s1 = "bdf" s2 = "bdgbdf" edges = {(1,'a') : 2,                (1,'b') : 3,       ...
Write in C programming language Write the function replace(char b[], char f[], char t[]). which finds...
Write in C programming language Write the function replace(char b[], char f[], char t[]). which finds the string 'f' in the string 'b' and replaces it with the string 't'. You can assume that f and t same length Example: char string[] = "zap";     replace(string, "ap", "oo"); --changes 'string' to "zoo".     *don't assume substring being replaced is singular, or that its own substrings are unique.     *Don't re scan letters already checked and replaced         char string[] =...
In Java, write a recursive function that accepts a string as its argument and prints the...
In Java, write a recursive function that accepts a string as its argument and prints the string in reverse order. Demonstrate the function in a driver program.
3. Write a function named "countNonAlpha" that accepts a string. It will return the number of...
3. Write a function named "countNonAlpha" that accepts a string. It will return the number of non-alphabet characters (excluding blanks) in the string. For example, if the string is "Hello, World!", it will return 2 for ',' and '!" in the string. 4. Write a function named "deleteZeros" that takes two arguments: a. an array of integer values; b. an integer for the number of elements in the array; The function will return the number of zeros that it has...
Write a C++ program (using the pthread library) that accepts a phrase of unspecified length on...
Write a C++ program (using the pthread library) that accepts a phrase of unspecified length on the command line. For example: prompt$: ./vowcon Operating Systems Class at CSUN The main() in this program should read the phrase from the terminal. This phrase can be read into a global variable. This phrase or its parts can be directly accessed from the main() and from the threads. The main() has to create two threads running functions (vow and con). The main() can...
C++ Please Define a function named "isAscending" that accepts a string as an input parameter and...
C++ Please Define a function named "isAscending" that accepts a string as an input parameter and returns "true" if all the characters included in the string are ordered in ascending order of their ASCII codes or the input string is a null string, and returns "false" otherwise. For example, if the string "ABXab" is passed to the function, it returns "true" because the ASCII code of 'B' is greater than 'A', 'X' is greater than 'B', 'a' is greater than...
C++: Write a student class for the library, which have the following: Username, password, Maximum number...
C++: Write a student class for the library, which have the following: Username, password, Maximum number of copies that a student is allowed to keep(less than 5), maximum borrow periods(less than 30 days per book), list of copy(array) cpp and h
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT