Package ua.com.jpy.services.auth.mongo.customer.password

Source Code of ua.com.jpy.services.auth.mongo.customer.password.PasswordEncoderService

package ua.com.jpy.services.auth.mongo.customer.password;

import java.security.NoSuchAlgorithmException;

import jonelo.jacksum.JacksumAPI;
import jonelo.jacksum.algorithm.AbstractChecksum;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.security.authentication.encoding.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
* @author LSD25
*
*/
@Service
public class PasswordEncoderService implements PasswordEncoder {
 
  private static final Log log = LogFactory.getLog(PasswordEncoderService.class);
 
  private static final String WHIRLPOOL = "whirlpool";
 
  @Override
  public String encodePassword(String rawPass, Object salt) {
    String encodedPassword = null;
    AbstractChecksum checksum = null;
    try {
      checksum = JacksumAPI.getChecksumInstance(WHIRLPOOL);
    } catch (NoSuchAlgorithmException exc) {
      log.error(null, exc);
      return null;
    }
    checksum.update(rawPass.getBytes());
    encodedPassword = checksum.getFormattedValue();
    return encodedPassword;
  }

  @Override
  public boolean isPasswordValid(String encPass, String rawPass, Object salt) {
    String encodeRawPass = encodePassword(rawPass, salt);
    return encodeRawPass.equals(encPass) ? true : false;
  }

}
TOP

Related Classes of ua.com.jpy.services.auth.mongo.customer.password.PasswordEncoderService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.