can i use hibernate to login jsp page using (session)
if i’m not using hibernate i do like this :
Username=request.getParameter("UserName");
Password=request.getParameter("passWord");
ResultSet s;
ResultSet resultat = stat1.executeQuery("select * from Etudinat where UserName ='"+ Username +"' and Password = '"+Password+"'");
if (resultat.next()) {
s = stat1.executeQuery("SELECT * FROM Etudinat where UserName ='"+Username+"'");
s.next();
ID = s.getInt("Id_Etudinat");
session.setAttribute("Id_Etudinat",ID);
session.setAttribute("UserName",Username);}
but with hibernate i want to know this step’s:
-when i get the request how can i test the username and password if they exist with hibernate ?
-if they exist do i put them with with session.setAttribute() or i can use some thing else with hibernate ??
you can use HQL, which is very similar to SQL. However, always use bound parameter. Like
where username=:username. Otherwise you risk sql injection. Also, you have to hash your passwords (rather than storing them in plaintext)You can place the
Userobject that you retrieve in the session.