Question

In: Computer Science

Please make it simply and easy for a beginner to follow.. -Write in C++ -Use Char...

Please make it simply and easy for a beginner to follow..

-Write in C++

-Use Char library functions

-Must show that is runs

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

#include <cctype>
#include <iostream>
#include <cstring>
using namespace std;

bool isValidPassword(char str[])
{
int len = strlen(str);
if(len<8)
return false;
int upper=0,lower=0,digit=0,special=0;
for(int i=0;i<len;i++)
{
if(isupper(str[i]))
upper++;
else if(islower(str[i]))
lower++;
else if(isdigit(str[i]))
digit++;
else
special++;
}
if(upper<1||lower<1||digit<1||special<1)
return false;
return true;
}
int main()
{
char str1[9]="Ab1@adf";
char str2[9]="Ab1@Bc2$";
char str3[9]="ab1@adfh";
char str4[9]="AB1@ADFH";
char str5[9]="Abb@adfh";
char str6[9]="Ab11adfh";
cout<<isValidPassword(str1)<<endl;
cout<<isValidPassword(str2)<<endl;
cout<<isValidPassword(str3)<<endl;
cout<<isValidPassword(str4)<<endl;
cout<<isValidPassword(str5)<<endl;
cout<<isValidPassword(str6)<<endl;
return 0;
}

//Program with input from user

#include <cctype>
#include <iostream>
#include <cstring>
using namespace std;

bool isValidPassword(char str[])
{
int len = strlen(str);
if(len<8)
return false;
int upper=0,lower=0,digit=0,special=0;
for(int i=0;i<len;i++)
{
if(isupper(str[i]))
upper++;
else if(islower(str[i]))
lower++;
else if(isdigit(str[i]))
digit++;
else
special++;
}
if(upper<1||lower<1||digit<1||special<1)
return false;
return true;
}
int main()
{
char str[100];
cout<<"Enter the password: ";
cin>>str;
if(isValidPassword(str))
cout<<"Valid";
else
cout<<"InValid";
return 0;
}


Related Solutions

Please make it simply and easy for a beginner to follow -Write in C++ -Use Char...
Please make it simply and easy for a beginner to follow -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 characte
C++ program, I'm a beginner so please make sure keep it simple Write a program to...
C++ program, I'm a beginner so please make sure keep it simple Write a program to read the input file, shown below and write out the output file shown below. Use only string objects and string functions to process the data. Do not use c-string functions or stringstream (or istringstream or ostringstream) class objects for your solution. Input File.txt: Cincinnati 27, Buffalo 24 Detroit 31, Cleveland 17 Kansas City 24, Oakland 7 Carolina 35, Minnesota 10 Pittsburgh 19, NY Jets...
Simple code please thats easy to follow. C++ Write a program that can be used to...
Simple code please thats easy to follow. C++ Write a program that can be used to compare Insertion Sort, Merge Sort and Quick Sort. Program must: Read an array size from the user, dynamically an array of that size, and fill the array with random numbers Sort the array with the Insertion Sort, MergeSort and QuickSort algorithms studied in class, doing a time-stamp on each sort. Use your program to measure and record the time needed to sort random arrays...
[ 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 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[] =...
Make a Binary search program for C# and write algorithm and explain it in easy words...
Make a Binary search program for C# and write algorithm and explain it in easy words also show output and input
-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
in c++ please follow instructions and fix the errors and please make a comment next to...
in c++ please follow instructions and fix the errors and please make a comment next to each code error you fix. Below are 25 code fragments, inserted into a try catch block. Each line has zero or more errors. Your task is to find and remove all errors in each fragment. Do not fix problems by simply deleting a statement; repair the problems by changing, adding, or deleting a few characters. There may be different ways to fix them You...
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
disadvantages of exports? (please write short and simply)
disadvantages of exports? (please write short and simply)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT