Note that there are some explanatory texts on larger screens.

plurals
  1. POJava code Check Password for Letter and Digit?
    primarykey
    data
    text
    <p>The first post was confusamagin. My assignment is to create a password prompt program. The password needs to be checked to see if it does have at least one digit and one letter in it. Also the password length must be between 6 - 10.</p> <p>My problem is trying to figure out how see if a digit and letter exist the password. In the check password area I am not sure where to begin really. I am not sure how to see if it has a Letter and a Digit in one. I know how to do either or by using a for statement to count and check but all it does is check to see rather it contains all letters or all digits.</p> <pre><code>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 &gt;&gt;"); 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 &gt;&gt;"); password = input.nextLine(); return password; } //--BOOLEAN CHECK PW public static boolean checkPassword(String password){ int length; length = password.length(); if (length &lt; 6 || length &gt; 11){ return false; } for (int i = 0; i &lt; password.length();i++){ if (!Character.isLetter(password.charAt(i))) return false; } return true; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload