package com.ds.listing.services;

import com.ds.listing.model.User;

import java.util.ArrayList;

import javax.ejb.Singleton;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Singleton
public class UserService {
  
  @PersistenceContext(unitName="primary")
  private EntityManager em;
  
  public User login(String userName, String password){
      Query query = em.createQuery("select u from User u where  u.name = :user AND u.failed < 4").setParameter("name", userName);
      User current = (User)query.getSingleResult();
      if(current.getPassword() == password){
          return current;
      }else{
          current.setFailed(current.getFailed()+1);
          return null;
      }
  }
  
}

@@ -278,16 +278,18 @@
 ce %7B%0A  %0A
+  
   @Persi
@@ -322,16 +322,18 @@
 imary%22)%0A
+  
   privat
@@ -355,16 +355,18 @@
  em;%0A  %0A
+  
   public
@@ -408,24 +408,119 @@
  password)%7B%0A
+        System.out.println(userName);%0A        System.out.println(password);%0A        try%7B%0A      
       Query 
@@ -585,16 +585,20 @@
  = :user
+name
  AND u.f
@@ -623,16 +623,20 @@
 ameter(%22
+user
 name%22, u
@@ -641,24 +641,30 @@
  userName);%0A
+      
       User c
@@ -703,16 +703,22 @@
 sult();%0A
+      
       if
@@ -760,24 +760,30 @@
 %7B%0A          
+ 
+     
 return curre
@@ -786,16 +786,22 @@
 urrent;%0A
+      
       %7De
@@ -815,16 +815,22 @@
         
+  
+    
 current.
@@ -869,24 +869,30 @@
 ;%0A          
+      
 return null;
@@ -892,16 +892,87 @@
 n null;%0A
+            %7D%0A        %7Dcatch (Exception e)%7B%0A            return null;%0A  
       %7D%0A

fix query