package cn.quantgroup.xyqb.controller.middleoffice.common;

import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.exception.DataException;
import cn.quantgroup.xyqb.util.PasswordUtil;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 密码校验策略
 */
@Component
public class PwdVerifyStrategy implements IVerifyStrategy {
    @Override
    public VerifyTypeEnum strategyName() {
        return VerifyTypeEnum.pwd;
    }

    @Override
    public void verify(User user, String verify) {
        String password = user.getPassword();
        if (Objects.equals(password, PasswordUtil.MD5WithSalt(verify))) {
            return;
        }
        //todo 自定义异常
        throw new DataException("用户名或密码错误");
    }
}
