Question

Convert this code written in Python to Java: username=input("please enter a username") password=input("please enter a password:")...

Convert this code written in Python to Java:

username=input("please enter a username")
password=input("please enter a password:")

def is_a password(password):
    count_uppercase, count_lowercase= 0, 0
    for characters1 in password:
        if characters1.isupper():
        count_uppercase += 1
        if characters1.islower():
        count_lowercase += 1
    is_password is good = True
    if len(password) <= 7:
        print "Passwords must be at least 8 characters long"
    is_password is good = False
    if count_uppercase < 1:
        print "Your password must contain at least one uppercase character"
        is_password is good = False
   if password.isalnum():
          print "Your password must contain at least one 'special' character"
        is_password is good = False
while (username == password):
print "You cannot use your username as part of your password"
         is_password is good = False

    print "Your password is valid!"
return is_password is good

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:


package passwords;

import java.util.Scanner;


public class Passwords {


public static boolean is_a_password(String password)
{
boolean is_password_good = false;
boolean result;
int count_uppercase=0,count_lowercase=0;
int special_character_count=0;
int number_count=0;
  
if(password.length()<=7)
{
System.out.println("Passwords must be atleast 8 characters long");
is_password_good = false;
return is_password_good;
}
for(int i=0;i<password.length();i++)
{
result=Character.isLetter(password.charAt(i));
if(result==true)
{
result=Character.isUpperCase(password.charAt(i));
if(result==true)
count_uppercase++;
  
result=Character.isLowerCase(password.charAt(i));
if(result==true)
count_lowercase++;
}
else
{
result=Character.isDigit(password.charAt(i));
  
if(result==true)
{
number_count++;
}
else
{
special_character_count++;
is_password_good=true;
}
}
  
}
  
if(special_character_count<1)
{
System.out.println("Your password must contain at least one 'special' character");
is_password_good=false;
return is_password_good;
}
else
is_password_good=true;
special_character_count=0;
  
  

if(count_uppercase<1)
{
System.out.println("Your password must contain at least one uppercase character");
is_password_good=false;
return is_password_good;
}
else
{
is_password_good=true;

}
  

return is_password_good;
}
  
public static void main(String[] args) {

String username;
String password;
boolean is_password_good;
  
Scanner sc = new Scanner(System.in);
  
System.out.println("Enter Username:");
username=sc.nextLine();
  
  
System.out.println("Enter Password:");
password=sc.nextLine();
  
  
while(username.equals(password))
{
System.out.println("You cannot use your username as part of your password");
System.out.println("Enter Password:");
password=sc.nextLine();
}
  
  
is_password_good = is_a_password(password);
  
if(is_password_good==true)
System.out.println("Your password is valid");
else
System.out.println("Your password is invalid");
  
  
}
  
}


======================================================================================

Output1:

Output 2:

Output 3:

Output 4:

======================================================================================

Screenshot of the code:

Add a comment
Know the answer?
Add Answer to:
Convert this code written in Python to Java: username=input("please enter a username") password=input("please enter a password:")...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Convert this code written in Python into Java: valid = False; while(valid == False):    username...

    Convert this code written in Python into Java: valid = False; while(valid == False):    username = input ("Please enter a username:")    length = len(username);    if(length < 8 or length > 15):        print("Username must be between 8 and 15 characters.")    else:               if(username.isalnum() == False):            print("Username must contain only alphanumeric characters.");        else:            count = 0;            inx = 0;           ...

  • Please make this Python code execute properly. User needs to create a password with at least...

    Please make this Python code execute properly. User needs to create a password with at least one digit, one uppercase, one lowercase, one symbol (see code), and the password has to be atleast 8 characters long. try1me is the example I used, but I couldn't get the program to execute properly. PLEASE INDENT PROPERLY. def policy(password): digit = 0 upper = 0 lower = 0 symbol = 0 length = 0 for i in range(0, len(password)): if password[i].isdigit(): # checks...

  • Write a program that asks the user to enter a password, and then checks it for...

    Write a program that asks the user to enter a password, and then checks it for a few different requirements before approving it as secure and repeating the final password to the user. The program must re-prompt the user until they provide a password that satisfies all of the conditions. It must also tell the user each of the conditions they failed, and how to fix it. If there is more than one thing wrong (e.g., no lowercase, and longer...

  • Create a Python Program that will ask the user for a password (use input) Verify that...

    Create a Python Program that will ask the user for a password (use input) Verify that the password meets the following conditions: -must be 12 characters long -must have uppercase and lowercase -must contain at least 1 special character (!~#$%^&*{}+_) -must be a mix of numbers and letters You must do this only using regular expressions so for instance this will not be accepted if len(password) <12: At the end of the program tell the user their password is ok...

  • Create a Python Program that will ask the user for a password (use input) Verify that...

    Create a Python Program that will ask the user for a password (use input) Verify that the password meets the following conditions: -must be 12 characters long -must have uppercase and lowercase -must contain at least 1 special character (!~#$%^&*{}+_) -must be a mix of numbers and letters You must do this only using regular expressions so for instance this will not be accepted if len(password) <12: At the end of the program tell the user their password is ok...

  • Write a code using python that simulates a Registration of a Username and Password with the...

    Write a code using python that simulates a Registration of a Username and Password with the following conditions the user can set its username display "Input username" input Username display "Input Password" input Password The password must be at least 5 characters and no longer than 10 characters if the password doesn't follow this instructions Display "Can't accept this password" once the password its stored Verify that the program works by Testing it input username Input Password The user has...

  • Python Create a function that checks user input in an attempt to create a password. The...

    Python Create a function that checks user input in an attempt to create a password. The valid_password function accepts a password as an argument and returns either true or false to indicate whether the password is valid. A valid password must be at least 7 characters in length, have at least one uppercase letter, one lowercase letter, and one digit. Respond with output to the user as to whether the password is valid or not, and allow the user to...

  • Please solve in Python. You would like to set a password for an email account. However,...

    Please solve in Python. You would like to set a password for an email account. However, there are two restrictions on the format of the password. It has to contain at least one uppercase character and it cannot contain any digits. You are given a string S consisting of N alphanumerical characters. You would like to find the longest substring of Sthat is a valid password. A substring is defined as a contiguous segment of a string. For example, given...

  • 8.4 in python function that checks whether a string is a valid password. Suppose the pas...

    8.4 in python function that checks whether a string is a valid password. Suppose the pas rules are as follows: . A password must have at least eight characters - A password must consist of only letters and digits. ■ A password must contain at least two 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 (Occurrences of a specified character) Write a function...

  • Good evening, I've been toiling around with restructuring a program which is supposed to register a...

    Good evening, I've been toiling around with restructuring a program which is supposed to register a preexisting input file, which contains four different passwords, and have it pass through the verification process, to see which of those passwords meets all the criteria set by the highlighted parameters. The code stipulates that in order for a password to be considered valid, it should contain a minimum of 6 characters in total, at least 2 lowercase letter, at least 1 uppercase letter,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT