2 * Copyright (C) 2016 quix0r
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.addressbook.validators.password;
19 import javax.faces.application.FacesMessage;
20 import javax.faces.component.UIComponent;
21 import javax.faces.context.FacesContext;
22 import javax.faces.validator.Validator;
23 import javax.faces.validator.ValidatorException;
24 import javax.inject.Inject;
25 import org.mxchange.addressbook.beans.login.UserLoginWebSessionController;
26 import org.mxchange.jcoreee.validator.string.BaseStringValidator;
27 import org.mxchange.jusercore.container.login.LoginContainer;
28 import org.mxchange.jusercore.container.login.UserLoginContainer;
29 import org.mxchange.jusercore.model.user.UserUtils;
32 * A validator for validating passwords (if they match with stored)
34 * @author Roland Haeder
36 public class UserPasswordValidator extends BaseStringValidator implements Validator {
41 private static final long serialVersionUID = 48_581_795_687_317L;
44 * User login controller
47 private UserLoginWebSessionController loginController;
50 public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
52 //this.getLogger().logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N
55 String[] requiredFileds = {"currentPassword"}; //NOI18N
57 // Pre-validation (example: not null, not a string, empty string ...)
58 super.preValidate(context, component, value, requiredFileds, false);
60 // value is known to be an entered password, so instance login container
61 LoginContainer container = new UserLoginContainer(this.loginController.getLoggedInUser(), (String) value);
64 if (!UserUtils.ifPasswordMatches(container, this.loginController.getLoggedInUser())) {
65 // Password mismatches
66 throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Password mismatching.", "The password the user has entered does not match the stored password.")); //NOI18N
70 //this.getLogger().logTrace("validate: EXIT!"); //NOI18N