source: trip-planner/src/main/java/finki/diplomska/tripplanner/validator/UserValidator.java

Last change on this file was 1ad8e64, checked in by Ema <ema_spirova@…>, 3 years ago

spring security

  • Property mode set to 100644
File size: 837 bytes
Line 
1package finki.diplomska.tripplanner.validator;
2
3import finki.diplomska.tripplanner.models.User;
4import org.springframework.stereotype.Component;
5import org.springframework.validation.Errors;
6import org.springframework.validation.Validator;
7
8
9@Component
10public class UserValidator implements Validator {
11 @Override
12 public boolean supports(Class<?> aClass) {
13 return User.class.equals(aClass);
14 }
15
16 @Override
17 public void validate(Object object, Errors errors) {
18 User user = (User) object;
19 if(user.getPassword().length() < 6){
20 errors.rejectValue("password","Length", "Password must be at least 6 characters" );
21 }
22 if(!user.getPassword().equals(user.getConfirmPassword())){
23 errors.rejectValue("confirmPassword", "Match", "Password must match");
24 }
25 }
26}
Note: See TracBrowser for help on using the repository browser.