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){
        try{
            Query query = em.createQuery("select u from User u where  u.name = :username AND u.failed < 4").setParameter("username", userName);
            User current = (User)query.getSingleResult();
            System.out.println(current.getPassword()+" - "+password);
            if(current.getPassword() == password){
                System.out.println("Success");
                return current;
            }else{
                current.setFailed(current.getFailed()+1);
                return null;
            }
        }catch (Exception e){
            System.out.println("error occurred");
            return null;
        }
  }
  
}

@@ -639,34 +639,18 @@
         
-System.out.println
+if
 (current
@@ -667,66 +667,16 @@
 rd()
-+%22 - %22+password);%0A            if(current.getPassword() == 
+.equals(
 pass
@@ -672,32 +672,33 @@
 equals(password)
+)
 %7B%0A              
@@ -726,16 +726,25 @@
 %22Success
+ful login
 %22);%0A    
@@ -790,16 +790,68 @@
  %7Delse%7B%0A
+                System.out.println(%22Failed login%22);%0A
         
@@ -900,16 +900,53 @@
 d()+1);%0A
+                em.persist(current);%0A
         

fix login