Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. I am trying to display a logged in user full name after login but need some direction.I already validated the user against the database but it only returns the email from the login.How to i get information about the logged in user. I have three classes the LoginDAO,Session and managedbean,the loginDAO includes the query to fetch the required information from the database
  2.  
  3.  
  4. public class LoginDAO {
  5. public static boolean validate (String user,String password) throws SQLException{
  6. Connection con = null;
  7. PreparedStatement ps = null;
  8.  
  9. try{
  10. con = DataConnect.getConnection();
  11. ps = con.prepareStatement("Select fname,lname,email, password from users where email = ? and password = MD5(?)");
  12. ps.setString(1, user);
  13. ps.setString(2, password);
  14.  
  15. ResultSet rs = ps.executeQuery();
  16.  
  17. if(rs.next()){
  18.  
  19. rs.getString("fname");
  20. rs.getString("lname");
  21. return true;
  22. }
  23. }catch (SQLException ex){
  24. System.out.println("Login error -->" +
  25. ex.getMessage());
  26. return false;
  27. }finally{
  28. DataConnect.close(con);
  29. }
  30. return false;
  31. }
  32.  
  33. private String fname;
  34. private String pwd;
  35. private String msg;
  36. private String user;
  37.  
  38. public String getFname() {
  39. return fname;
  40. }
  41.  
  42. public void setFname(String fname) {
  43. this.fname = fname;
  44. }
  45.  
  46. public String getPwd() {
  47. return pwd;
  48. }
  49.  
  50. public void setPwd(String pwd) {
  51. this.pwd = pwd;
  52. }
  53.  
  54. public String getMsg() {
  55. return msg;
  56. }
  57.  
  58. public void setMsg(String msg) {
  59. this.msg = msg;
  60. }
  61.  
  62. public String getUser() {
  63. return user;
  64. }
  65.  
  66. public void setUser(String user) {
  67. this.user = user;
  68. }
  69.  
  70. return "login";
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement