I just started with java a few weeks ago, and am trying to make a program to verify that a password is at least 10 characters, has at least one each of:upper case, lower case, number, and is only alphanumeric characters.
Below is the code I have so far. It’s more English than code actually, but what I’m trying to do is run several loops under one boolean (at least that’s what I think I’m doing). Can you help me understand how exactly booleans work, and if it’s possible for several conditions to be tested under one boolean, as I’m trying to do below?
Thanks!
public class validatingPassword
{
public static void main(String[] args)
{
String password= isSecurePassword("testcase");
System.out.println(isSecurePassword);
}
public static boolean isSecurePassword(String password)
{
password.charAt(x);
int lengthPassword= password.length();
if (lengthPassword < 10);
return false;
for (int x = 0; x < lengthPassword; x++)
{
if ('A' <=x && x <= 'Z');}
else if
return false;
for (int x = 0; x< lengthPassword; x++)
{
('a' <=x && x <= 'z'); }
else if
return false:
for (int x = 0; x < lengthPassword; x++)
{
('0' <=x && x <= '9');}
return true;
}
else if
{
x++;
return false;
}
}
}
I just give the correct code undocumented. Because I think you’ve got the right ideas, but are missing a bit of Java syntax. You might debug the code with single-step through all commands.