Question

In: Computer Science

Write a program that validates passwords based on the following requirements: • must be at least...

Write a program that validates passwords based on the following requirements:
• must be at least 8 characters in length
• must include at least 1 alphabet character
• must include at least 1 number

The program should implement the password checker using a function name validate_password,
which takes two strings as input and returns one of the following:
• 0 if the passwords match and fulfill all requirements
• 1 if the passwords are not the same length
• 2 if the a number is not found
• 3 if an alphabet character is not found

In main, test your function validate_password by creating 4 sets of passwords and which match one of the conditions listed above and printing the result.

In C program

Solutions

Expert Solution


#include <stdio.h>
#include <string.h>

int validate_password(char *str){
    int letters=0,digits=0;;
     if(strlen(str)<8){
       return 1;
    }
    for(int i=0;i<str[i]!='\0';i++){
        if( (str[i]>='A' && str[i]<='Z') || (str[i]>='a' && str[i]<='z') )
            letters=1;
        if(str[i]>='0' && str[i]<='9')
            digits=1;
    }
   if(!digits)
    return 2;
   if(!letters)
   return 3;
   
   return 0;
   
}
void printRes(int n){
    switch(n){
        case 0:printf("Valid Password\n");break;
        case 1:printf("Password length is less than 8 chars\n");break;
        case 2:printf("Password does not contain digits\n");break;
        case 3:printf("Password does not contain characters\n");break;
    }
}
int main()
{
  char str[20];
  printf("Enter Password : ");
  scanf("%s",str);
  printRes(validate_password(str));
  printf("Enter Password : ");
  scanf("%s",str);
  printRes(validate_password(str));
  printf("Enter Password : ");
  scanf("%s",str);
  printRes(validate_password(str));
  printf("Enter Password : ");
  scanf("%s",str);
  printRes(validate_password(str));
    
   

}


Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Write a program that validates passwords based on the following requirements: • must be at least...
Write a program that validates passwords based on the following requirements: • must be at least 8 characters in length • must include at least 1 alphabet character • must include at least 1 number The program should implement the password checker using a function name validate_password, which takes two strings as input and returns one of the following: • 0 if the passwords match and fulfill all requirements • 1 if the passwords are not the same length •...
c++ Develop a program that validates a password entered by a user. The password must meet...
c++ Develop a program that validates a password entered by a user. The password must meet the following criteria: Be at least six characters long. Contain at least one uppercase and at least one lowercase letter. Have at least one digit. Write a program that asks for a password and then verifies that it meets the stated criteria. If it does not, the program should display a message telling the user why and ask for another password. The program should...
Program Requirements: Write a C++ program according to the following requirements: 1.   Open the data file...
Program Requirements: Write a C++ program according to the following requirements: 1.   Open the data file Electricity.txt and read each column into an array (8 arrays total). 2.   Also create 2 arrays for the following: Total Fossil Fuel Energy (sum of all fossil fuels) Total Renewable Energy (sum of all renewable sources) Electricity.txt: Net generation United States all sectors monthly https://www.eia.gov/electricity/data/browser/ Source: U.S. Energy Information Administration All values in thousands of megawatthours Year   all fuels   coal       natural gas   nuclear  ...
Write a program which: Prompts the user for a positive integer >= 0 Validates the user...
Write a program which: Prompts the user for a positive integer >= 0 Validates the user input to ensure it is a positive integer >= 0 Allocate (dynamically) an array big enough for the data. Load the array with random numbers ranging in value from1 to 100 Display the elements of the array (unsorted) Display the elements of the array (sorted) Display the average Display the median Display the mode, if none, display appropriate message RESTRICTIONS No global variables No...
To write a C++ program for following scenario and display requirements: Scenario-based Problem: AIG Insurance wants...
To write a C++ program for following scenario and display requirements: Scenario-based Problem: AIG Insurance wants to create an insurance management system for their clients. The insurance management system will compute the required payments from the clients. The commission of the agent shall also be computed which depends on the amount of insurance type. Insurance Type Amount of Insurance type Agent Commission Life 2500 12.5% of amount Health 1500 10.5% of amount Other inputs 0 0 Computation of monthly payments...
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
The following information describes the requirements for your response: It must be at least three paragraphs...
The following information describes the requirements for your response: It must be at least three paragraphs long (more is usually better), grammatically correct, and demonstrate that you understand and can apply the concepts covered in the second competency module. When writing your response, follow the steps listed below in the order that they appear. Step One: Begin by describing the process for calculating price elasticity of demand. Then, using fictitious numbers, calculate the price elasticity of demand for donuts at...
Write any java programming to meet the following requirements. Your project must meet the following requirements:...
Write any java programming to meet the following requirements. Your project must meet the following requirements: 1. Specify input specification      Design input 2. Specify Output Specification     Design Output 3. The class must include set methods and get methods ( with or without parameters both) 4. Must include Array structure 5. Must include Input or Output Files or both 6. Demonstrate your knowledge of an Applet
1. Write a Java program from scratch that meets the following requirements: a. The program is...
1. Write a Java program from scratch that meets the following requirements: a. The program is in a file called Duplicates.java that defines a class called Duplicates (upper/lower case matters) b. The program includes a Java method called noDuplicates that takes an array of integers and returns true if all the integers in that array are distinct (i.e., no duplicates). Otherwise it returns false. Make sure the method is public static. example tests: noDuplicates({}) returns true noDuplicates({-1, 1}) returns true...
Write a program in c++, with at least four functions, including main, which must do the...
Write a program in c++, with at least four functions, including main, which must do the following: Ask user whether they want to encode or decode a message – if no, then terminate Take the input string from the user, store it in dynamic memory (use new) As appropriate, encode or decode the message using Rot13. Output the encoded/decoded message Delete the input string from dynamic memory (use delete) Input will be a string of no more than 25 characters....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT