Well after much search on the subject I ended up coming to this method:
public boolean verificar(String login, String senha) {
try {
Usuarios usuarios = this.jdbcTemplate.queryForObject(queryPorLogin, new Object[]{login},
new RowMapper<Usuarios>() {
public Usuarios mapRow(ResultSet rs, int rowNum) throws SQLException {
Usuarios user = new Usuarios();
if(BCrypt.checkpw(senha, rs.getString("senha"))) {
user.setIdUsuario(rs.getLong("idUsuario"));
user.setLogin(rs.getString("login"));
user.setSenha(rs.getString("senha"));
}
return user;
}
});
if(usuarios.getIdUsuario() != null) {
System.out.println(usuarios.toString());
return true;
}else {
return false;
}
}catch (EmptyResultDataAccessException e) {
System.out.println("Senha errada");
return false;
}
}
i first select in the database, and if the password encrypted with bcrypt is equal to the password entered I will set the user and then make a check if the user id is different from null ( if it returns a true, which I will use in my controller)
Catch (Emptyresultdataaccessexception e) {
System.out.println("Wrong password");
Return false;
}
the catch I searched a lot because before I was not using the Try catch and when there was no result generated a joptionpane error.
In case anyone can help me where to improve on the code I would be grateful!
Some reason not to set up a
AuthenticationManager
using Spring Security?– nullptr
@nullptr did not know of the existence of the same, but I have already managed to solve this method ( I will seek to know what server )
– Joao Spirit
it would be interesting for the community if you answered your own question when you were able to solve the problem, your answer can contribute to solving the problem of other people in the future
– nullptr
@nullptr opa I did not know I had this possibility I will answer now.
– Joao Spirit
@nullptr ready bro, I didn’t know there was such a possibility, if you can take a look and see where I can improve .
– Joao Spirit