View Javadoc
1   package org.itracker.services.authentication;
2   
3   import org.itracker.PasswordException;
4   import org.itracker.model.util.UserUtilities;
5   import org.springframework.security.crypto.password.PasswordEncoder;
6   
7   
8   public class ITrackerPasswordEncoder implements PasswordEncoder {
9       @Override
10      public String encode(CharSequence rawPassword) {
11          try {
12              return UserUtilities.encryptPassword(String.valueOf(rawPassword));
13          } catch (PasswordException e) {
14              throw new IllegalArgumentException(e);
15          }
16      }
17  
18      @Override
19      public boolean matches(CharSequence rawPassword, String encodedPassword) {
20          if (null == rawPassword || rawPassword.length() < 1 || null == encodedPassword) {
21              return false;
22          }
23          String pw = encode(rawPassword);
24  
25          return pw.equals(encodedPassword);
26      }
27  }