cn.hutool.crypto.digest.DigestUtil Java Examples

The following examples show how to use cn.hutool.crypto.digest.DigestUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserController.java    From feiqu-opensource with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@PostMapping("updatePass")
public Object updatePass(FqUser queryUser, HttpServletRequest request, HttpServletResponse response) {
    BaseResult baseResult = new BaseResult();
    FqUserCache currUser = webUtil.currentUser(request,response);
    if(currUser == null){
        baseResult.setResult(ResultEnum.USER_NOT_LOGIN);
        return baseResult;
    }
    if(!currUser.getId().equals(queryUser.getId())){
        baseResult.setResult(ResultEnum.USER_NOT_SAME);
        return baseResult;
    }
    if(queryUser.getPassword().length() < 6){
        baseResult.setResult(ResultEnum.PASSWORD_LENGTH_ERROR);
        return baseResult;
    }
    queryUser.setPassword(DigestUtil.md5Hex(queryUser.getPassword()));
    userService.updateByPrimaryKeySelective(queryUser);
    return baseResult;
}
 
Example #2
Source File: RegistLoginController.java    From uccn with Apache License 2.0 6 votes vote down vote up
/**
 * 用户注册
 * @param user
 * @return
 */
@RequestMapping(value = "/regist", method = RequestMethod.POST)
public MessageResult regist(@RequestBody User user){
    if (user == null || StringUtils.isBlank(user.getName()) || StringUtils.isBlank(user.getPassword())){
        return MessageResult.errorMsg("用户名或者密码不能为空");
    }

    boolean isExist = userService.queryUsernameIsExist(user.getName());
    if (isExist){
        return MessageResult.errorMsg("用户名已存在");
    }else {
        user.setPassword(DigestUtil.md5Hex(user.getPassword()));

        userService.saveUser(user);
    }

    List<User> userList = userService.queryUsernameAndPassWord(user.getName(), user.getPassword());

    UserVo userVo = setUserRedisSessionToken(userList.get(0));
    userVo.setPassword("");

    return MessageResult.ok(userVo);
}
 
Example #3
Source File: MerkleTree.java    From md_blockchain with Apache License 2.0 6 votes vote down vote up
/**
 * return Node Hash List.
 *
 * @param tempTxList
 * list
 * @return
 * 某一层的左右节点相连hash
 */
private List<String> getNewTxList(List<String> tempTxList) {
    List<String> newTxList = new ArrayList<>();
    int index = 0;
    while (index < tempTxList.size()) {
        // left
        String left = tempTxList.get(index);
        index++;
        // right
        String right = "";
        if (index != tempTxList.size()) {
            right = tempTxList.get(index);
        }
        // sha2 hex value
        String sha2HexValue = DigestUtil.sha256Hex(left + right);
        newTxList.add(sha2HexValue);
        index++;
    }

    return newTxList;
}
 
Example #4
Source File: RedisTemplateConfig.java    From albedo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 自定义缓存key生成策略,默认将使用该策略
 */
@Bean
@Override
public KeyGenerator keyGenerator() {
	return (target, method, params) -> {
		Map<String, Object> container = new HashMap<>(3);
		Class<?> targetClassClass = target.getClass();
		// 类地址
		container.put("class", targetClassClass.toGenericString());
		// 方法名称
		container.put("methodName", method.getName());
		// 包名称
		container.put("package", targetClassClass.getPackage());
		// 参数列表
		for (int i = 0; i < params.length; i++) {
			container.put(String.valueOf(i), params[i]);
		}
		// 转为JSON字符串
		String jsonString = JSON.toJSONString(container);
		// 做SHA256 Hash计算,得到一个SHA256摘要作为Key
		return DigestUtil.sha256Hex(jsonString);
	};
}
 
Example #5
Source File: CryptionKit.java    From kvf-admin with MIT License 5 votes vote down vote up
/**
 * 生成并加密密码
 * @param pwd
 * @return
 */
public static String genUserPwd(String pwd) {
    if (StrUtil.isEmpty(pwd)) {
        return genUserPwd();
    }
    return DigestUtil.md5Hex(pwd);
}
 
Example #6
Source File: RegistLoginController.java    From uccn with Apache License 2.0 5 votes vote down vote up
/**
 * 用户登录
 * @param user
 * @return
 */
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public MessageResult login(@RequestBody User user) {
    MessageResult respMessage = new MessageResult();
    if (user == null || StringUtils.isBlank(user.getName()) || StringUtils.isBlank(user.getPassword())){
        respMessage.setCode(-1);
        respMessage.setMsg("用户名或者密码不能为空");
        logger.info("error : 用户名或者密码不能为空");
        return respMessage;
    }

    List<User> userList = userService.queryUsername(user.getName());
    if (userList == null || userList.size() == 0){
        respMessage.setCode(-1);
        respMessage.setMsg("用户不存在!");
        logger.info("error : 用户不存在");
        return respMessage;
    }

    User user1 = userList.get(0);
    if (!user1.getPassword().equals(DigestUtil.md5Hex(user.getPassword()))){
        respMessage.setCode(-1);
        respMessage.setMsg("用户或密码不正确!");
        logger.info("error : 用户或密码不正确");
        return respMessage;
    }

    UserVo userVo = setUserRedisSessionToken(user1);
    userVo.setPassword("");
    respMessage.setData(userVo);

    CookieUtil.addCookie("userToken", userVo.getUserToken());
    CookieUtil.addCookie("userId", userVo.getId());
    logger.info("userToken : " + userVo.getUserToken());

    return respMessage;
}
 
Example #7
Source File: UserController.java    From feiqu-opensource with Apache License 2.0 4 votes vote down vote up
@ResponseBody
@PostMapping(value = "/login")
public BaseResult dologin(HttpServletRequest request, FqUser user, HttpServletResponse response,
                          String remember, String redirectSuccessUrl, String verifyCode) {
    BaseResult result = new BaseResult();
    try {
        String ip = WebUtil.getIP(request);
        logger.info("login:登陆用户详情:{},ip:{}",user.toString(),ip);
        if (StringUtils.isBlank(user.getUsername()) || StringUtils.isBlank(user.getPassword())) {
            result.setResult(ResultEnum.PARAM_NULL);
            return result;
        }
        if(StringUtils.isNotEmpty(verifyCode) && !verifyCode.equals(request.getSession().getAttribute("code"))){
            result.setResult(ResultEnum.VERIFY_CODE_NOT_CORRECT);
            return result;
        }
        FqUserExample FqUserExample = new FqUserExample();
        FqUserExample.createCriteria().andUsernameEqualTo(user.getUsername())
                .andPasswordEqualTo(DigestUtil.md5Hex(user.getPassword()));
        FqUser userDB = userService.selectFirstByExample(FqUserExample);
        if (userDB != null) {
            if(UserStatusEnum.FROZEN.getValue().equals(userDB.getStatus())){
                result.setResult(ResultEnum.USER_FROZEN);
                return result;
            }
            WebUtil.loginUser(request, response, userDB, "on".equals(remember));
            result.setResult(ResultEnum.SUCCESS);
            if (StringUtils.isNotBlank(redirectSuccessUrl)) {
                result.setData(redirectSuccessUrl);
            }else {
                result.setData(CommonConstant.DOMAIN_URL+"/u/"+userDB.getId()+"/home");
            }
            return result;
        } else {
            result.setResult(ResultEnum.USERNAME_OR_PASSWORD_ERROR);
            logger.info("用户未查到");
            return result;
        }
    } catch (Exception e) {
        logger.error("login error", e);
    }
    return result;
}
 
Example #8
Source File: Test1.java    From feiqu-opensource with Apache License 2.0 4 votes vote down vote up
@Test
public void test6(){
    Console.log(DigestUtil.md5Hex("123456"));
}
 
Example #9
Source File: PasswordTest.java    From uccn with Apache License 2.0 4 votes vote down vote up
@Test
public void test1(){
    String password = "123456";
    String hex = DigestUtil.md5Hex(password);
    System.out.println(hex);
}
 
Example #10
Source File: Block.java    From md_blockchain with Apache License 2.0 4 votes vote down vote up
/**
 * 根据该区块所有属性计算sha256
 * @return
 * sha256hex
 */
private String calculateHash() {
    return DigestUtil.sha256Hex(
                    blockHeader.toString() + blockBody.toString()
    );
}
 
Example #11
Source File: Sha256.java    From md_blockchain with Apache License 2.0 4 votes vote down vote up
public static String sha256(String input) {
    return DigestUtil.sha256Hex(input);
}
 
Example #12
Source File: CryptionKit.java    From kvf-admin with MIT License 2 votes vote down vote up
/**
 * 【作用】生成初始密码<br>
 * 【说明】系统用户密码
 * @param
 * @author Kalvin
 * @Date 2018/1/4 17:14
 */
public static String genUserPwd() {
    return DigestUtil.md5Hex(SysConstant.DEFAULT_PWD);
}