0% found this document useful (0 votes)
29 views

Write A Java Program To Accept Name and Password?

This Java program accepts a username and password from the user. It prompts the user to enter a password, checks that the password is between 6-10 characters long and only contains letters, and then prompts the user to re-enter the password to verify it matches the first entry. If the password criteria is met and the passwords match, it prints a confirmation message.

Uploaded by

Jeremy Kipgen
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Write A Java Program To Accept Name and Password?

This Java program accepts a username and password from the user. It prompts the user to enter a password, checks that the password is between 6-10 characters long and only contains letters, and then prompts the user to re-enter the password to verify it matches the first entry. If the password criteria is met and the passwords match, it prints a confirmation message.

Uploaded by

Jeremy Kipgen
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 1

Write a Java program to accept name and password? Answer: import java.util.

Scanner; class Password { public static void main(String[] args) { Scanner input = new Scanner(System.in); //------ENTER A USERNAME System.out.println("Welcome please enter your username and password."); System.out.print("Username >>"); input.nextLine(); //------PASSWORD AUTHENTICATION BEGIN String password = enterPassword(); while ( !checkPassword(password) ) { System.out.println("Password must be 6 - 10 characters long!"); password = enterPassword(); } //------PASSWORD VERIFY String passwordverify = enterPassword(); while (!password.equals(passwordverify)){ System.out.println("ERROR - Passwords DO NOT MATCH Re-Enter Passwords Again"); password = enterPassword(); } //------ACCEPT PASSWORD System.out.println("Username and Password Accepted!"); } //--ENTER PASSWORD STATEMENT public static String enterPassword(){ String password; Scanner input = new Scanner(System.in); System.out.print("Password >>"); password = input.nextLine(); return password; } //--BOOLEAN CHECK PW public static boolean checkPassword(String password){ int length; length = password.length(); if (length < 6 || length > 11){ return false; } for (int i = 0; i < password.length();i++){ if (!Character.isLetter(password.charAt(i))) return false; } return true; }

You might also like