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

In c++ Write a function that: accepts a string and an integer as it's only arguments...
In c++ Write a function that: accepts a string and an integer as it's only arguments uses the argument to open a file for writing writes the integer to the file if it fails to open the file, returns -1 if it succeeds in opening the file, returns 0 does not interact with the user in any way does not use global variables
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...
note: USE C++ WITH USER DEFINED FUNCTIONS AND RECURSIVE FUNCTION ONLY. No C++ library function is...
note: USE C++ WITH USER DEFINED FUNCTIONS AND RECURSIVE FUNCTION ONLY. No C++ library function is allowed. The game of “Jump It” consists of a board with n positive integers in a row, except for the first column, which always contains zero. These numbers represent the cost to enter each column. Here is a sample game board where n is 6: 0 3 80 6 57 10 The object of the game is to move from the first column to...
[ 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[] =...
Please write code in c++ using iostream library. Also you can use any string library. Create...
Please write code in c++ using iostream library. Also you can use any string library. Create structure plane with the following: 1)plane's ID[int type] 2) location[char*] 3) departure time[char*] Your task is to find the plane with the smallest departure time for the selected city. Pointer, dynamic array and structures have to be used in this code. Input: NOTE: It's just an example of input, you should write code generally for any inputs. First line contains n(0 < n <...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT