I wrote a program that works well, but not perfectly. The program asks the user to enter a password then checks the password to make sure it is between 6 and 10 characters in length, and contains at least 1 letter and 1 number. If the password meets those requirements, the user is alerted that the password is "good". If it does not meet the requirements, the user is alerted that the password is no good, and they need to try again. All of this works fine, but I need the program to KEEP asking for a password until one is given that meets the requirements. Right now, it only asks one time, and gives the result.

Also, once a password meets the requirements, the user is to type it again to verify that it matches the original password typed. This works fine as well, but it also needs to keep asking until the passwords match.

Can anyone help me out on this? I am not sure the best way to do this. I am new to Java, and trying to teach myself with a book I have purchased. Thanks.

Here is the code:

Code:
import java.util.Scanner;
public class PasswordChecker
{

	// Create main method
	public static void main(String[] args)
	{
		// Declare variables
		Scanner sc = new Scanner(System.in);
		int letters = 0;
		int digits = 0;
		
		
		// Prompt user to enter a possible password
		System.out.println("Please enter a possible password.");
		String password = sc.nextLine();
		int len = password.length();     // Determines the lenght of the password
		
		// Check to see if the password contains at least one number and one letter
		for (int i=0;i<password.length();++i)
		{
			char c=password.charAt(i);
			if (Character.isLetter(c)) ++letters;
			if (Character.isDigit(c)) ++digits;
		}		
		
		// Check to see that the password is between 6 and 10 characters long, and contains 1 letter and 1 number, minimum
		// If the password meets the criteria, alert user. If not, ask user to enter a new password
		if (len < 6 || len > 10 || letters == 0 || digits == 0)		
			System.out.println("Passwords must be between 6 and 10 characters in lenght, and contain at least 1 letter, and 1 number. Please try again.");		
		else		
			System.out.println("This is a good password. Please re-enter your password for verification.");
						
		
		// If the password is "good", compare the 2 passwords to see if they match, and report results to the user
		String password2 = sc.nextLine();
		
		if (password.equals(password2))
			System.out.println("Congratulations, the passwords match.");
		else
			System.out.println("The passwords do not match. Please try again");	
		
	}

}