Hello,I want to add an authentication i.e login using email and password for users.I don't know how to do it using session and entity bean. Although I am able to insert data in database using session and entity bean and servlet.

I am using glassfish server and connection pooling.

Here is the login page(login.jsp)

Java Code:
<form action="<c:url value="oauthlogin" />" method=post >
        <div id="loginBox">
            <p><strong>Email:</strong>
                <input type="text" size="20" name="email"></p>
     
            <p><strong>Password:</strong>
                <input type="password" size="20" name="password"></p>
     
            <p><input type="submit" value="Login"> <a href="<c:url value="signup" />">Create your account here</a></p>
        </div>
    </form>
Here is the Controller Servlet(ControllerServlet.java)

Java Code:
package entity;
     
    import java.io.Serializable;
    import javax.persistence.Basic;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.Table;
    //import javax.validation.constraints.NotNull;
    import javax.validation.constraints.Size;
    import javax.xml.bind.annotation.XmlRootElement;
     
    /**
     *
     * @author Rakesh Kumar
     */
    @Entity
    @Table(name = "login")
    @XmlRootElement
    @NamedQueries({
        @NamedQuery(name = "Login.findAll", query = "SELECT l FROM Login l")
        , @NamedQuery(name = "Login.findById", query = "SELECT l FROM Login l WHERE l.id = :id")
        , @NamedQuery(name = "Login.findByName", query = "SELECT l FROM Login l WHERE l.name = :name")
        , @NamedQuery(name = "Login.findByEmail", query = "SELECT l FROM Login l WHERE l.email = :email")
        , @NamedQuery(name = "Login.findByPassword", query = "SELECT l FROM Login l WHERE l.password = :password")
        , @NamedQuery(name = "Login.findByConfirmPassword", query = "SELECT l FROM Login l WHERE l.confirmPassword = :confirmPassword")})
    public class Login implements Serializable {
     
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Basic(optional = false)
        //@NotNull
        @Column(name = "id")
        private Integer id;
        @Basic(optional = false)
        //@NotNull
        @Size(min = 1, max = 45)
        @Column(name = "name")
        private String name;
        // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
        @Basic(optional = false)
        //@NotNull
        @Size(min = 1, max = 45)
        @Column(name = "email")
        private String email;
        @Basic(optional = false)
        //@NotNull
        @Size(min = 1, max = 45)
        @Column(name = "password")
        private String password;
        @Basic(optional = false)
        //@NotNull
        @Size(min = 1, max = 45)
        @Column(name = "confirm_password")
        private String confirmPassword;
     
        public Login() {
        }
     
        public Login(Integer id) {
            this.id = id;
        }
     
        public Login(Integer id, String name, String email, String password, String confirmPassword) {
            this.id = id;
            this.name = name;
            this.email = email;
            this.password = password;
            this.confirmPassword = confirmPassword;
        }
     
        public Integer getId() {
            return id;
        }
     
        public void setId(Integer id) {
            this.id = id;
        }
     
        public String getName() {
            return name;
        }
     
        public void setName(String name) {
            this.name = name;
        }
     
        public String getEmail() {
            return email;
        }
     
        public void setEmail(String email) {
            this.email = email;
        }
     
        public String getPassword() {
            return password;
        }
     
        public void setPassword(String password) {
            this.password = password;
        }
     
        public String getConfirmPassword() {
            return confirmPassword;
        }
     
        public void setConfirmPassword(String confirmPassword) {
            this.confirmPassword = confirmPassword;
        }
     
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (id != null ? id.hashCode() : 0);
            return hash;
        }
     
        @Override
        public boolean equals(Object object) {
            // TODO: Warning - this method won't work in the case the id fields are not set
            if (!(object instanceof Login)) {
                return false;
            }
            Login other = (Login) object;
            if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
                return false;
            }
            return true;
        }
     
        @Override
        public String toString() {
            return "entity.Login[ id=" + id + " email=" + email + " passoword = " + password + " ]";
        }
         
    }
and Session bean(LoginManager.java)

Java Code:
@Stateless
    @TransactionManagement(TransactionManagementType.CONTAINER)
    public class LoginManager {
        Login login = new Login();
       @PersistenceContext(unitName = "AffableBeanPU")
       private EntityManagerFactory emf;
       private EntityManager em;
       public int Register(String name, String email, String password, String confirmPassword){
        try{
             
             
            login.setName(name);
            login.setEmail(email);
            login.setPassword(password);
            login.setConfirmPassword(confirmPassword);
             
            em.persist(login);
            em.flush();
            return login.getId();
        }catch(Exception ex){
            ex.printStackTrace();
        }
           return 0;
    }
     
     
        public List<Login> getDetails() {        
          return em.createQuery("select email,password from login").getResultList();
       }
       }
Please tell me what code should I write in session bean and controller servlet to achieve the authentication.