Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @FacesValidator("confirmPasswordValidator")
- public class ConfirmPasswordValidator implements Validator {
- @Override
- public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
- UIInput passwordComponent = (UIInput) component.getAttributes().get("passwordComponent");
- String password = (String) passwordComponent.getValue();
- String confirmPassword = (String) value;
- if (confirmPassword != null && !confirmPassword.equals(password)) {
- throw new ValidatorException(new FacesMessage(
- FacesMessage.SEVERITY_ERROR, "Confirm password is not the same as password", null));
- }
- }
- }
- private String password;
- // Getter+setter.
- public String login() {
- User user = userService.find(username, password);
- if (user != null) {
- FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("user", user);
- return "success?faces-redirect=true";
- } else {
- FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(
- FacesMessage.SEVERITY_WARN, "Unknown login, please try again.", null));
- return null;
- }
- }
- <navigation-rule>
- <description>
- Login
- </description>
- <from-view-id>/Login.jsp</from-view-id>
- <navigation-case>
- <from-outcome>login_success</from-outcome>
- <to-view-id>/Success.jsp</to-view-id>
- </navigation-case>
- <navigation-case>
- <from-outcome>login_failed</from-outcome>
- <to-view-id>/Login_failed.jsp</to-view-id>
- </navigation-case>
- </navigation-rule>
- public String login(){
- //Compare login and password against a DB, file, etc.
- if(entered_password.equals(stored_passwd){
- return "login_success";
- }else{
- return "login_failed";
- }
- }
- <h:commandbutton value="LOGIN" action="#{Beans.login}" />
- String pass1 ="#s27zaiyt0";
- String pass2 ="#s27zaiyt0";
- sysout(pass1.equals(pass2));
Add Comment
Please, Sign In to add comment