web application in JAVA Primefaces MongoDB - regex on validation password during registration user
Budget: €8 – €9 EUR
hi i have a very stupid question, i have a primefaces project and i need to add a control of valdidation registration user password at the return starment of method. actually there is the user already present control, i need just add another control about the password that need respect > 8 character etc.
this is the part of code:
@Service
public class UserService {
@Autowired
UserRepository userRepository;
public List<UserEntity> findAll() {
List<UserEntity> users = new ArrayList<UserEntity>();
userRepository.findAll().toIterable().forEach(user -> {
users.add(user);
});;
return users;
}
//PASSWORD VALIDATION digit + lowercase char + uppercase char + punctuation + symbol
private static final String PASSWORD_PATTERN =
"^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#&()–[{}]:;',?/*~$^+=<>]).{8,20}$";
private static final Pattern pattern = Pattern.compile(PASSWORD_PATTERN);
public static boolean isValid(final String password) {
Matcher matcher = pattern.matcher(password);
return matcher.matches();
}
public Flux<Response> register(String email, String password) {
boolean passwordIsValid = false;
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
UserEntity user = userRepository.findAll().blockFirst() == null ? new UserEntity(
) : new UserEntity();
user.setEmail(email);
user.setPassword(encoder.encode(password));
user.setActive(true);
//PASSWORD VALIDATION
if (!isValid(password)) {
return Response.Error("digit + lowercase char + uppercase char + punctuation + symbol > 8 characters");
}
return userRepository
.findByEmail(user.getEmail())
.map(result -> {
return Response.Error("Email used from another user.");
})
.switchIfEmpty(userRepository
.save(user)
.map(result -> {
return Response.Success();
}));
}
this is the part of code:
@Service
public class UserService {
@Autowired
UserRepository userRepository;
public List<UserEntity> findAll() {
List<UserEntity> users = new ArrayList<UserEntity>();
userRepository.findAll().toIterable().forEach(user -> {
users.add(user);
});;
return users;
}
//PASSWORD VALIDATION digit + lowercase char + uppercase char + punctuation + symbol
private static final String PASSWORD_PATTERN =
"^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#&()–[{}]:;',?/*~$^+=<>]).{8,20}$";
private static final Pattern pattern = Pattern.compile(PASSWORD_PATTERN);
public static boolean isValid(final String password) {
Matcher matcher = pattern.matcher(password);
return matcher.matches();
}
public Flux<Response> register(String email, String password) {
boolean passwordIsValid = false;
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
UserEntity user = userRepository.findAll().blockFirst() == null ? new UserEntity(
) : new UserEntity();
user.setEmail(email);
user.setPassword(encoder.encode(password));
user.setActive(true);
//PASSWORD VALIDATION
if (!isValid(password)) {
return Response.Error("digit + lowercase char + uppercase char + punctuation + symbol > 8 characters");
}
return userRepository
.findByEmail(user.getEmail())
.map(result -> {
return Response.Error("Email used from another user.");
})
.switchIfEmpty(userRepository
.save(user)
.map(result -> {
return Response.Success();
}));
}
Related categories:
Business, Accounting, Human Resources & Legal
JavaScript
J2EE
Software Architecture
XHTML