Question: Could you kindly check and fix my code please? I cannot get it to work. PLEASE FOLLOW MY CODE STRICTLY WITHOUT CHANGING IT ENTIRELY! Problem:

Could you kindly check and fix my code please? I cannot get it to work. PLEASE FOLLOW MY CODE STRICTLY WITHOUT CHANGING IT ENTIRELY!

Problem: Some websites impose certain rules for passwords. Write a method that checks whether a string is a valid password. Suppose the password rules are as follows: A password must have at least techaracters. A password consists of only letters and digits. A password must contain at least three digits. Write a program that prompts the user to enter a password and displays "Valid Password" if the rules are followed or "Invalid Password" otherwise.

My code:

import java.util.*; public class Exercise06_18 { public static void main(String[] args) { // Create a scanner class Scanner input = new Scanner(System.in); // Prompt the user to enter three integers System.out.println("Please enter a password: "); String password = input.next(); checkPassword(password); } public static void checkPassword(String pass) { int digitCount = 0; boolean passwordCondition = true; if(pass.length() < 10) { passwordCondition = false; } for(int i = 0; i < pass.length(); i++) { if(!(Character.isDigit(pass.charAt(i)))) { passwordCondition = false; } if(!(Character.isLetter(pass.charAt(i)))) { passwordCondition = false; } if((Character.isLetter(pass.charAt(i)))) { passwordCondition = false; digitCount++; } if (digitCount < 3) { passwordCondition = false; } } if(passwordCondition = true) { System.out.println("Valid password. "); } else if(passwordCondition = false) { System.out.println("Invalid password. "); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!