BCrypt实现注册加密

版权声明:转载请标明出处 https://blog.csdn.net/keyuzhang/article/details/89283721

1.Controller层

@RestController
@RequestMapping("seller")
public class SellerController {
    @Reference
    private SellerService sellerService;
    @RequestMapping("/add")
    public Result add(@RequestBody Seller seller){
        try{
            sellerService.add(seller);
            return new Result(true,"保存成功");
        }catch(Exception e){
            return new Result(false,"保存失败");
        }
    }
}

2.Service层

public void add(Seller seller) {
    //设置商家默认为未审核 0
    seller.setStatus("0");
    //使用BCrypt对密码进行加密
    BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
    seller.setPassword(bCryptPasswordEncoder.encode(seller.getPassword()));

    sellerDao.insertSelective(seller);
}

ps:如何校对加密后的的密码会在(Security+BCrypt加密算法实现登录验证)一文中验证

猜你喜欢

转载自blog.csdn.net/keyuzhang/article/details/89283721