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 •...
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...
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  ...
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
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....
[JAVA] You will write a program to validate passwords for users, making sure they meet the...
[JAVA] You will write a program to validate passwords for users, making sure they meet the following criteria: Rules: Passwords must be at least 8 characters long Passwords can only contain alpha numeric characters (no spaces or special characters) Passwords must contain at least 1 uppercase character Passwords must contain at least 1 lowercase character Passwords must contain at least 1 numeric character (0-9) Passwords cannot contain the word “password” A password that does not meet all of these rules...
Write one Java program and satisfy the following requirements: Write a method called cube that accepts...
Write one Java program and satisfy the following requirements: Write a method called cube that accepts one integer parameter and returns that value raised to the third power. Write a method called randomNumber that returns a random floating-point number in the range of [-20.0, 50.0). (hints: use Random class in the method) Write a method called findMax that accepts three floating-point number as parameters and returns the largest one.(hints: use conditional statement in the method) Overload findMax that accepts one...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT