Question

In: Computer Science

[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 must list each rule that it breaks.
You must repeatedly ask the user for a password until the user enters “endofinput”

This question was posted before however it used methods and I am not able to use methods for this assignment

Solutions

Expert Solution

Given below is the code for the question. Please do rate the answer if it helped. Thank you.

import java.util.Scanner;

public class PasswordValidator {
   public static void main(String[] args) {
       Scanner input = new Scanner(System.in);
       String password;
       System.out.print("Enter password: ");
       password = input.nextLine();

       boolean alphanumOk, ucaseOk, lcaseOk, digitOk;
       while(!password.equals("endofinput")) {
           if(password.contains("password"))
               System.out.println("Password should not contain the word 'password'");
           if(password.length() < 8)
               System.out.println("Password should be atleast 8 characters long");

           alphanumOk = true;
           ucaseOk = false;
           lcaseOk = false;
           digitOk = false;

           for(int i = 0; i < password.length(); i++) {
               char c = password.charAt(i);
               if(Character.isUpperCase(c))
                   ucaseOk = true;
               else if(Character.isLowerCase(c))
                   lcaseOk = true;
               else if(Character.isDigit(c))
                   digitOk = true;
               else
                   alphanumOk = false;
           }

           if(!alphanumOk)
               System.out.println("Passoword can not contain special characters. Only alphanumeric characters allowed");
           if(!lcaseOk)
               System.out.println("Password should contain atleast one lower case letter");
           if(!ucaseOk)
               System.out.println("Password should contain atleast one upper case letter");
           if(!digitOk)
               System.out.println("Password should contain atleast one digit");
           if(alphanumOk && lcaseOk && ucaseOk && digitOk)
               System.out.println("Password is good");


           System.out.print("Enter password: ");
           password = input.nextLine();

       }      
   }
}


Related Solutions

Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks...
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks for a password, then asks again to confirm it. If the passwords don’t match or the rules are not fulfilled, prompt again. Your program should include a method that checks whether a password is valid. From that method, call a different method to validate the uppercase, lowercase, and digit requirements for a valid password. Your program should contain at least four methods in addition...
Write JAVA program that finds 3 students with the best scores. The program asks users for...
Write JAVA program that finds 3 students with the best scores. The program asks users for scores of 5 students. The program prints the first, second, third place students and scores. You can assume that there is no two students with the same score. <EXAMPLE> enter the score of each student score of student 1: 50 score of student 2: 70 score of student 3: 30 score of student 4: 90 score of student 5: 40 1st place is student...
Java please! Write the code in Exercise.java to meet the following problem statement: Write a program...
Java please! Write the code in Exercise.java to meet the following problem statement: Write a program that will print the number of words, characters, and letters read as input. It is guaranteed that each input will consist of at least one line, and the program should stop reading input when either the end of the file is reached or a blank line of input is provided. Words are assumed to be any non-empty blocks of text separated by spaces, and...
Write a Java Program using the concept of objects and classes. Make sure you have two...
Write a Java Program using the concept of objects and classes. Make sure you have two files Employee.java and EmployeeRunner.java. Use the template below for ease. (Please provide detailed explanation) Class Employee Class Variables: Name Work hour per week Hourly payment Class Methods: - Get/Sets - generateAnnualSalary(int:Duration of employment)               annual salary = Hourly payment * Work hours per week * 50 If the employee is working for more than 5 years, 10% added bonus             -void displayAnnualSalary ( )...
I'm making a python program that checks the users input. If the users input does not...
I'm making a python program that checks the users input. If the users input does not match the rules then the program will output "No". If the users input does match the rules it will output "Yes". The rules are : at least 5 uppercase letters at least 5 lowercase letters at least 5 numbers No more than 20 characters in total I have managed to meet these conditions in individual python files but not in one. Ideally without importing...
I'm making a python program that checks the users input. If the users input does not...
I'm making a python program that checks the users input. If the users input does not match the rules then the program will output "No". If the users input does match the rules it will output "Yes". The rules are : 5 uppercase letters 5 lowercase letters 5 numbers First letter must be capitilized The total characters must be 15 I have managed to meet these conditions in individual python files but not in one. Ideally without importing anything, still...
Write a program to validate parenthesis of any given equation by using the following criteria (you...
Write a program to validate parenthesis of any given equation by using the following criteria (you MUST use stacks); Number of open parenthesis “(“must be same as number of close parentheses “)” For example if I input “3 + 4 * (98+34*(34+8)*34*(3+x)” the program should display an error message, because number of open parenthesis “(“is 3 and number of closed “)” parenthesis is 2. Stack-Driver.cpp: #include "stack.h" #include "stack.cpp" #include<stdio.h> #include<stdlib.h> #include<time.h> int main() {    stack<int> my_stack(100);    srand(time(NULL));...
Write the program in java Write a program that does basic encrypting of text. You will...
Write the program in java Write a program that does basic encrypting of text. You will ask the user the filename of a text file which contains a few sentences of text. You will read this text file one character at a time, and change each letter to another one and write out to an output file. The conversion should be done a -> b, b->c , … z->a, A->B, B->C, …. Z->A. This means just shift each letter by...
XML and JAVA Write a Java program that meets these requirements. It is important you follow...
XML and JAVA Write a Java program that meets these requirements. It is important you follow these requirements closely. • Create a NetBeans project named LastnameAssign1. Change Lastname to your last name. For example, my project would be named NicholsonAssign1. • In the Java file, print a welcome message that includes your full name. • The program should prompt for an XML filename to write to o The filename entered must end with .xml and have at least one letter...
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 •...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT