wassup! ok i am new to this forum and would like to ask someing i am having trouble with my end of the PAT mark ( practical assessment task) ok so we need to make a password checker that allows the user to enter a password and then the program checks if it meets certain criteria in this case the criteria is as follows : Must have between 5-15 characters it must include both letters and numbers and cannot contain vowels this is my code so far ( a bit messy i know but work with me here)
public class Password {
public static void main(String[] args) {
String pass;
String pass1 = "T";
String pass2 = "T";
String pass3 = "F";
pass = JOptionPane.showInputDialog("Please input a password that meets the following criteria :"
+ "\n1. Must include both letters and numbers"
+ "\n2. Must be between 5-15 characters"
+ "\n3. Must contain no vowels");
int length = (pass.length());
if (length < 4 ||length > 20)
{
pass1 = "T";
}
if ("T".equals(pass1))
{
for (int i = 0; i <= length; i++)
{
if (pass.charAt(i) == 'a' ||pass.charAt(i) == 'A'||pass.charAt(i) == 'e'||pass.charAt(i) == 'E' ||
pass.charAt(i) == 'i' || pass.charAt(i) == 'I' || pass.charAt(i) == 'o' || pass.charAt(i) == 'O'||pass.charAt(i) == 'u'||
pass.charAt(i) == 'U')
{
pass2 = "F";
}
}
}
if ("T".equals(pass1))
{
}
if ("F".equals(pass2));
{
JOptionPane.showMessageDialog(null, "Sorry your password does not comply with the criteria");
}
if ("F".equals(pass1))
{
}
}
ok and this is the highly frustrating error i a recieving :
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 5
at java.lang.String.charAt(String.java:687)
at DeathStrike.Password.main(Password.java:33)
Java Result: 1
please help guys!