I'm doing a project for school and I need to make a password verifier (I.e, longer than 8 chars, not using invalid chars). The code will be finished when I figure out how to fix the dead code issue:
import java.util.Scanner;
class Main {
static boolean valid = false;
static void password(String pass) {
String[] ivp = {"!","@","#","$", "%", "^", "^", "&", "*", "(", ")", "~", "`","\"", "'", "/", "<",">",",", ".", "/", "\\", ";", ":", "{", "}", "[", "]","?", "+", "=", "_", "-"};
for (int j = 0; j < ivp.length; j++) {
if (pass.length() < 8) {
System.out.println("Password must have at least eight characters.");
valid = false;
}
if (pass.contains(ivp[j])) {
System.out.println("Password must only contain letters and digits.");
valid = false;
}
else {
System.out.println("Password accepted!");
valid = true;
}
if (valid); {
break;
}
}
}
public static void main(String[] args) {
String sn = "";
Scanner scn = new Scanner(System.in);
while(!valid) {
System.out.print("Enter a string: ");
sn = scn.nextLine();
password(sn);
}
}
}
What I have tried:
putting a semicolon after the partese the if statements.