Guest User

Untitled

a guest
Jan 15th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. @FacesValidator("confirmPasswordValidator")
  2. public class ConfirmPasswordValidator implements Validator {
  3.  
  4. @Override
  5. public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
  6. UIInput passwordComponent = (UIInput) component.getAttributes().get("passwordComponent");
  7. String password = (String) passwordComponent.getValue();
  8. String confirmPassword = (String) value;
  9.  
  10. if (confirmPassword != null && !confirmPassword.equals(password)) {
  11. throw new ValidatorException(new FacesMessage(
  12. FacesMessage.SEVERITY_ERROR, "Confirm password is not the same as password", null));
  13. }
  14. }
  15.  
  16. }
  17.  
  18. private String password;
  19.  
  20. // Getter+setter.
  21.  
  22. public String login() {
  23. User user = userService.find(username, password);
  24.  
  25. if (user != null) {
  26. FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("user", user);
  27. return "success?faces-redirect=true";
  28. } else {
  29. FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(
  30. FacesMessage.SEVERITY_WARN, "Unknown login, please try again.", null));
  31. return null;
  32. }
  33. }
  34.  
  35. <navigation-rule>
  36. <description>
  37. Login
  38. </description>
  39. <from-view-id>/Login.jsp</from-view-id>
  40. <navigation-case>
  41. <from-outcome>login_success</from-outcome>
  42. <to-view-id>/Success.jsp</to-view-id>
  43. </navigation-case>
  44. <navigation-case>
  45. <from-outcome>login_failed</from-outcome>
  46. <to-view-id>/Login_failed.jsp</to-view-id>
  47. </navigation-case>
  48. </navigation-rule>
  49.  
  50. public String login(){
  51. //Compare login and password against a DB, file, etc.
  52.  
  53. if(entered_password.equals(stored_passwd){
  54. return "login_success";
  55. }else{
  56. return "login_failed";
  57. }
  58. }
  59.  
  60. <h:commandbutton value="LOGIN" action="#{Beans.login}" />
  61.  
  62. String pass1 ="#s27zaiyt0";
  63. String pass2 ="#s27zaiyt0";
  64. sysout(pass1.equals(pass2));
Add Comment
Please, Sign In to add comment