package cn.edu.whu.boot.common.utils.user;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

/**
 * 对密码进行 hash
 * 算法：SHA-256
 * 迭代： 2 次
 * 盐：UUID
 */
public class PasswordEncoder {
    private static final String ALGORITHM = "SHA-256";

    private static final int ITERATION = 2;

    public static String getALGORITHM() {
        return ALGORITHM;
    }

    public static int getITERATION() {
        return ITERATION;
    }

    public static String encode(String password, String salt) {
        return new SimpleHash(ALGORITHM, password, ByteSource.Util.bytes(salt), ITERATION).toHex();
    }
}