[Solved] Password input program [closed]


You have a logic error in your compare() method.

When you use one = you are doing an assignment, not a comparison:

if (passCompare = true) // assigns true to passCompare and always evaluates true
    return true;
else
    return false;

More fundamentally, don’t reinvent the wheel. The String class already has a perfectly good way to check to see if two Strings are equal: the equals() method.

Instead of this:

do {
    pInput2 = JOptionPane.showInputDialog(null, "Please re-enter your password: \n");

    }
while (compare(pInput, pInput2) == false);

if (compare(pInput, pInput2) == true) {
    //if input is validated and returns true- finish program
    JOptionPane.showMessageDialog(null, "Your password was successfully entered.");
}

…you could instead do this:

    do {
        pInput2 = JOptionPane.showInputDialog(null, "Please re-enter your password: \n");
    } while (!pInput.equals(pInput2));

    if (pInput.equals(pInput2)) {
        //if input is validated and returns true- finish program
        JOptionPane.showMessageDialog(null, "Your password was successfully entered.");
    }

This would let you do away with your compare() method altogether, which removes to opportunity to make mistakes in it.

1

solved Password input program [closed]