code: @Override
      public String checkPassword(String userSecurityName, @Sensitive String password) throws RegistryException {
          if (userSecurityName == null) {
              throw new IllegalArgumentException("userSecurityName is null");
          }
          if (userSecurityName.isEmpty()) {
              throw new IllegalArgumentException("userSecurityName is an empty String");
          }
          if (password == null) {
              throw new IllegalArgumentException("password is null");
          }
          if (password.trim().isEmpty()) {
              throw new IllegalArgumentException("password is an empty String");
          }
          boolean valid = false;
  
          BasicPassword storedPassObj = null;
          if (state.ignoreCaseForAuthentication) {
              for (Map.Entry<String, BasicPassword> entry : state.users.entrySet()) {
                  String keyUserName = entry.getKey();
                  if (keyUserName.equalsIgnoreCase(userSecurityName)) {
                      storedPassObj = entry.getValue();
                  }
              }
          } else {
              storedPassObj = state.users.get(userSecurityName);
          }
  
          if (storedPassObj != null) {
              if (!storedPassObj.isHashed()) {
                  ProtectedString inPass = new ProtectedString(password.toCharArray());
                  ProtectedString storedPass = storedPassObj.getPassword();
                  if (storedPass != null && storedPass.equals(inPass)) {
                      valid = true;
                  }
              } else {
                  String storedPass = storedPassObj.getHashedPassword();
                  if (storedPass != null) {
                      HashMap<String, String> props = new HashMap<String, String>();
                      props.put(PasswordUtil.PROPERTY_HASH_ENCODED, storedPass);
                      String inPass = null;
                      try {
                          inPass = PasswordUtil.encode(password, PasswordUtil.getCryptoAlgorithm(storedPass), props);
                      } catch (Exception e) {
                          //fail to encode password.
                          throw new IllegalArgumentException("password encoding failure : " + e.getMessage());
                      }
                      if (storedPass.equals(inPass)) {
                          valid = true;
                      }
                  }
              }
          }
          if (valid) {
              return userSecurityName;
          } else {
              return null;
          }
      }
docs: {@inheritDoc}