Question

Imagine you are developing a software package that requires users to enter their own passwords. Read...

Imagine you are developing a software package that requires users to enter their own passwords. Read the input as a C-string or a string object. Your software requires that users’ passwords be sent to special functions that will verify if the characters used meet the following criteria:

  • The password should be at least six characters long.

  • The password should contain at least one uppercase and at least one lowercase letter.

  • The password should have at least one digit.

Write a program that asks for a password then verifies that it meets the stated criteria. If it doesn’t, the program should display a message telling the user why.

You may consider using various functions such as the following ...

void displayRequirements();
void displayResult(char[]);
bool isValid(char[]);
bool hasLength(char[]);
bool hasLower(char[]);
bool hasUpper(char[]);
bool hasDigit(char[]);

or implement your own functional decomposition.

Sample Screen Output (user input in bold):

Password Requirements:
  - The password should be at least 6 characters long.
  - The password should contain at least one uppercase
    and at least one lowercase letter.
  - The password should have at least one digit.

Enter a password: srjc
The password is invalid.

It should be at least 6 characters long.
It should contain at least one uppercase letter.
It should have at least one digit.

Enter another password: srjc2020
The password is invalid.

It should contain at least one uppercase letter.

Enter another password: Srjc2020
The password is valid.

Process returned 0 (0x0)   execution time : 37.238 s
Press any key to continue.

Homework Answers

Answer #1

/******************************************************************************

Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>
#include <string.h>
#include <time.h>
#include<stdbool.h>
void displayRequirements() //function to display requirements
{
printf("\nPassword Requirements:");
printf("\n - The password should be at least 6 characters long.");
printf("\n- The password should contain at least one uppercase and at least one lowercase letter.");
printf("\n - The password should have at least one digit");
}
bool hasLower(char ch[100])
{
int count=0;
for(int i=0;i<strlen(ch);i++)
{
if(ch[i]>='a' && ch[i]<='z') //check for lower Case Character presence
count=1;
}
if(count==1)
return true;
else
return false;
}
bool hasUpper(char ch[100])
{
int count=0;
for(int i=0;i<strlen(ch);i++)
{
if(ch[i]>='A' && ch[i]<='Z') //check for Upper Case Character present
count=1;
}
if(count==1)
return true;
else
return false;
}
bool hasDigit(char ch[100])
{
int count=0;
for(int i=0;i<strlen(ch);i++)
{
if(ch[i]>='0' && ch[i]<='9') //check for digit
count=1;
}
if(count==1)
return true;
else
return false;
}
bool hasLength(char ch[100])
{
if(strlen(ch)>=6) //check if length is greater than 6
return true;
else
return false;
}
void displayResult(char pass[100])
{
  
bool invalid=true;
int error=0,k=0;
while(invalid) //while loop to run till the user enter a valid input
{
error=0; //reset error value with every iteration
if(k>0) //check to see if user has entered password for first time to ask enter password again
{
printf("\nEnter another password: ");
scanf("%s",pass);
}
if(!hasLength(pass)) //check password length if true below checks are performed
{
if(error==0) // if there is no error before displaying invalid password
{
error=1;
printf("The password is invalid.\n\n");
}
printf("It should be at least 6 characters long.\n");
}
if(!hasLower(pass)) // check to see if password has a lowercase character
{
if(error==0) // if there is no error before displaying invalid password
{
error=1;
printf("The password is invalid.\n\n");
}
printf("It should contain at least one lowercase letter.\n");
}
if(!hasUpper(pass)) //check to see if there is a uppercase character
{
if(error==0)
{
error=1; // if there is no error before displaying invalid password
printf("The password is invalid.\n\n");
}
printf("It should contain at least one uppercase letter.\n");
}
if(!hasDigit(pass)) //check to see if password has a digit
{
if(error==0)
{
error=1;
printf("The password is invalid.\n\n");
}
printf("It should have at least one digit.\n");
}
if(error==0) //if there is no error password is valid
{
printf("The password is valid.\n\n");   
invalid=false;
}
k++; //k increased to check if it first input entry
}
  
}
int main()
{

char pass[100];
  
clock_t ts=clock; //start time to calculate Execution time Taken
displayRequirements(); // display Requirement to User
printf("\n\nEnter a password: ");
scanf("%s",pass); // Taking user input
displayResult(pass); //Display Result to user
  
clock_t t = clock() ; //Calculating time after exection
double time_taken = ((double)ts-t)/CLOCKS_PER_SEC;
printf("\nProcess returned 0 (0x0) execution time : %f s",time_taken);

return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Using Python, generate a random password which meets these rules and show five examples of the...
Using Python, generate a random password which meets these rules and show five examples of the random passwords. rules: password contains 6-20 characters, contain at least one lowercase letter, at least one uppercase letter, and at least one digit, must not contain three repeating characters in a row ("...aaa..." is weak, but "...aa...a..." is strong, assuming other conditions are met).
2) Allowing (or requiring) users to use numerical digits (including 0) and one of 28 “special...
2) Allowing (or requiring) users to use numerical digits (including 0) and one of 28 “special characters” dramatically increases the number of possible passwords. Furthermore, passwords often are case-sensitive, effectively doubling the size of the alphabet by defining 52 distinct letter characters.    Assuming that passwords are case-sensitive and can include numerical digits and special characters, how many possible 6, 8 and 10 character passwords can be created? (8 points) 3) Allowing digits and special characters creates an enormous number...
1- A particular automatic sprinkler system has two different types of activation devices for each sprinkler...
1- A particular automatic sprinkler system has two different types of activation devices for each sprinkler head. One type has a reliability of 0.87; that is, the probability that it will activate the sprinkler when it should is 0.87. The other type, which operates independently of the first type, has a reliability of 0.77. If either device is triggered, the sprinkler will activate. Suppose a fire starts near a sprinkler head. a) What is the probability that the sprinkler head...
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...
COBOL Translate English to Pig Latin This interactive program translates any word the user enters into...
COBOL Translate English to Pig Latin This interactive program translates any word the user enters into Pig Latin. The interactive session --------------------------------------------- Enter any word to see what it looks like in Pig Latin. To quit, type Uitqay. --------------------------------------------- string The Pig Latin equivalent is: Ingstray --------------------------------------------- unstring The Pig Latin equivalent is: Unstringlay --------------------------------------------- Uitqay Oodbyegay! Specifications • If the word starts with a consonant, move the consonants before the first vowel to the end of the word and...
//evil_server.cpp #include <string> #include <cstdlib> #include <iostream> #include "evil_server.h" using namespace std; EvilServer :: EvilServer() {...
//evil_server.cpp #include <string> #include <cstdlib> #include <iostream> #include "evil_server.h" using namespace std; EvilServer :: EvilServer() {    hacked[0] = hacked[1] = hacked[2] = false;    passwords[agent_index(MrMean)] = random_pw(MrMean);    passwords[agent_index(MsChief)] = random_pw(MsChief);    passwords[agent_index(DrEvil)] = random_pw(DrEvil); } void EvilServer :: change_pw(EvilAgent agent, string new_pw) {    int index = agent_index(agent);    if (new_pw == passwords[index])        return;    hacked[index] = false;    passwords[index] = new_pw; } string EvilServer :: random_pw(EvilAgent agent) {    string password;    int length;   ...
is there anything wrong with the solution. the question are from java course Write a main...
is there anything wrong with the solution. the question are from java course Write a main method that will request the user to enter Strings using a JOptionPane input dialog. The method should continue accepting strings until the user types “STOP”.       Then, using a JOptionPane message dialog, tell the user how many of the strings begin and end with a digit. Answer: import javax.swing.*; public class IsAllLetters {     public static void main(String[] args) {         String input;         int count =...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
USING PYTHON do all the he problems using while loop , continue and break 1-This problem...
USING PYTHON do all the he problems using while loop , continue and break 1-This problem provides practice using a while True loop.write a function named twoWords that gets and returns two words from a user. The first word is of a specified length, and the second word begins with a specified letter.The function twoWords takes two parameters: an integer, length, that is the length of the first word and a character, firstLetter, that is the first letter of the...