Check password fields with each other in java in spring

Asked

Viewed 122 times

0

How do I validate two password fields if both are equal

Usuario usuario = (Usuario) target;
        if(usuario.getSenha().equals(usuario.getSenha2())) {
                    errors.rejectValue("senha2", "field.compare");
                }
  • 2

    Gerson, edit your post and put in the formatted code. Other than that, your code is already comparing the two passwords, so I don’t quite understand what your question is.

2 answers

1

Do more or less like this man.

campo1.getText();
    campo2.getText();

    if(campo1.equals("campo2")){
    //Executa função para senha igual
    }else{
    //Executa função para senhas diferentes
     }

0

if((campo1.getPassword()+"").equals(campo2.getPassword()+"")){
    //verdadeiro
}else{
    //falso
}

Try not to use the getText() in fields Jpasswordfield, because it was discontinued for that element.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.