0
I’m trying to do a GET to validate a user using Cpf and password,using DAO, but I’m not sure when to pass the parameter.
Follow the get code
private Usuario usuarioLogado;
@GET
@Path("/{cpf}/{senha}")
public String Autenticar(@PathParam("cpf") String cpf,@PathParam("senha") String senha ) {
UsuarioDAO usuarioDAO = new UsuarioDAO();
usuarioLogado = usuarioDAO.autenticar(cpf, senha);
Gson gson = new Gson();
String json = gson.toJson(usuarioLogado);
return json; }
Follows the DAO
public Usuario autenticar(String cpf, String senha) {
Session sessao = hibernateUtil.getFabricaDeSessoes().openSession();
try{
Criteria consulta = sessao.createCriteria(Usuario.class);
consulta.createAlias("pessoa", "p");
consulta.add(Restrictions.eq("p.cpf", cpf));
SimpleHash hash = new SimpleHash("md5", senha);
consulta.add(Restrictions.eq("senha", hash.toHex()));
Usuario resultado = (Usuario) consulta.uniqueResult();
return resultado;
} catch (RuntimeException erro) {
throw erro;
} finally {
sessao.close();
}
}
And what is your doubt?
– nullptr
Anyway it is a bad practice you pass the open password through your GET URL.
– nullptr
So, this I imagined, and I wanted to know how I can do this authentication without passing the password URL.
– thiago eza
My question is whether there would be another way to do this authentication consultation.
– thiago eza