public boolean checkPassword(String userName, String password) { System.out.println("checkPassword " + password); User usr = null; String qry = "select u from User u where u.userName = '******'"; System.out.println("Query = " + qry); if (em != null) { List<User> users = em.createQuery(qry, User.class).setFirstResult(0).setMaxResults(1).getResultList(); System.out.println("Query uitgevoerd"); if (users != null) { System.out.println("Er lijkt resultaat"); if (!users.isEmpty()) { System.out.println("Proberen te lezen"); usr = users.get(0); System.out.println("User gevonden : " + usr.getUserName()); System.out.println("User password = "******"password ok"); return true; } else { System.out.println("password niet ok"); return false; } } else { System.out.println("Toch geen resultaat"); return false; } } else { return false; } } else { System.out.println("EntityManager em = null"); return false; } }
public ReturnStatus askpassword(String email, String userName) { System.out.println("askpassword"); User usr = null; String qry = "select u from User u where u.userName = '******'"; System.out.println("Query = " + qry); // Valideer correctheid email try { javax.mail.internet.InternetAddress ia = new javax.mail.internet.InternetAddress(email); ia.validate(); } catch (javax.mail.internet.AddressException e) { return new ReturnStatus(false, "email is niet juist formaat (server controlled)."); } List<User> users = em.createQuery(qry, User.class).setFirstResult(0).setMaxResults(1).getResultList(); System.out.println("Query uitgevoerd"); if (users != null) { System.out.println("Er lijkt resultaat"); if (!users.isEmpty()) { System.out.println("Proberen te lezen"); usr = users.get(0); System.out.println("User gevonden : " + usr.getUserName()); if (usr.getEmail().equalsIgnoreCase(email)) { System.out.println("email ok"); String message = "Uw password voor username " + userName + " is : " + usr.getPassword(); boolean result = emailBean.sendEmailSSL(email, "password aanvraag", message); if (result) { return new ReturnStatus(true, "Mail verzonden"); } else { return new ReturnStatus(true, "Mail niet verzonden"); } } else { System.out.println("email is niet hetzelfde : " + usr.getEmail() + " en " + email); return new ReturnStatus( false, "email is niet hetzelfde : " + usr.getEmail() + " en " + email); } } else { System.out.println("Toch geen resultaat"); return new ReturnStatus(false, "gebruiker is niet bekend"); } } else { System.out.println("User niet gevonden"); return new ReturnStatus(false, "gebruiker is niet bekend"); } }