Java Code Examples for cn.hutool.crypto.SecureUtil#md5()

The following examples show how to use cn.hutool.crypto.SecureUtil#md5() . 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: GlobalUserServiceImpl.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * @param data
 * @return
 */
@Override
@Transactional(rollbackFor = Exception.class)
public GlobalUser save(GlobalUserSaveDTO data) {
    BizAssert.equals(data.getPassword(), data.getConfirmPassword(), "2次输入的密码不一致");
    isFalse(check(data.getAccount()), "账号已经存在");

    String md5Password = SecureUtil.md5(data.getPassword());

    GlobalUser globalAccount = BeanPlusUtil.toBean(data, GlobalUser.class);
    // 全局表就不存用户数据了
    globalAccount.setPassword(md5Password);
    globalAccount.setName(StrHelper.getOrDef(data.getName(), data.getAccount()));
    globalAccount.setReadonly(false);

    save(globalAccount);
    return globalAccount;
}
 
Example 2
Source File: OpenApiInterceptor.java    From Jpom with MIT License 6 votes vote down vote up
private boolean checkOpenApi(HttpServletRequest request, HttpServletResponse response) {
    String header = request.getHeader(ServerOpenApi.HEAD);
    if (StrUtil.isEmpty(header)) {
        ServletUtil.write(response, JsonMessage.getString(300, "token empty"), MediaType.APPLICATION_JSON_UTF8_VALUE);
        return false;
    }
    String authorizeToken = ServerExtConfigBean.getInstance().getAuthorizeToken();
    if (StrUtil.isEmpty(authorizeToken)) {
        ServletUtil.write(response, JsonMessage.getString(300, "not config token"), MediaType.APPLICATION_JSON_UTF8_VALUE);
        return false;
    }
    String md5 = SecureUtil.md5(authorizeToken);
    md5 = SecureUtil.sha1(md5 + ServerOpenApi.HEAD);
    if (!StrUtil.equals(header, md5)) {
        ServletUtil.write(response, JsonMessage.getString(300, "not config token"), MediaType.APPLICATION_JSON_UTF8_VALUE);
        return false;
    }
    return true;
}
 
Example 3
Source File: AdminUiService.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
/**
 * 超管账号登录
 *
 * @param account  账号
 * @param password 密码
 * @return
 */
public R<AuthInfo> adminLogin(String account, String password) {
    String basicHeader = ServletUtil.getHeader(WebUtils.request(), BASIC_HEADER_KEY, StrPool.UTF_8);
    String[] client = JwtUtil.getClient(basicHeader);

    GlobalUser user = this.globalUserService.getOne(Wrappers.<GlobalUser>lambdaQuery()
            .eq(GlobalUser::getAccount, account).eq(GlobalUser::getTenantCode, BizConstant.SUPER_TENANT));
    // 密码错误
    if (user == null) {
        throw new BizException(ExceptionCode.JWT_USER_INVALID.getCode(), ExceptionCode.JWT_USER_INVALID.getMsg());
    }

    String passwordMd5 = SecureUtil.md5(password);
    if (!user.getPassword().equalsIgnoreCase(passwordMd5)) {
        return R.fail("用户名或密码错误!");
    }
    JwtUserInfo userInfo = new JwtUserInfo(user.getId(), user.getAccount(), user.getName());

    AuthInfo authInfo = tokenUtil.createAuthInfo(userInfo, null);
    log.info("token={}", authInfo.getToken());
    return R.success(authInfo);
}
 
Example 4
Source File: GlobalUserServiceImpl.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * @param data
 * @return
 */
@Override
@Transactional(rollbackFor = Exception.class)
public GlobalUser update(GlobalUserUpdateDTO data) {
    if (StrUtil.isNotBlank(data.getPassword()) || StrUtil.isNotBlank(data.getPassword())) {
        BizAssert.equals(data.getPassword(), data.getConfirmPassword(), "2次输入的密码不一致");
    }

    GlobalUser globalUser = BeanPlusUtil.toBean(data, GlobalUser.class);
    if (StrUtil.isNotBlank(data.getPassword())) {
        String md5Password = SecureUtil.md5(data.getPassword());
        globalUser.setPassword(md5Password);

    }
    updateById(globalUser);
    return globalUser;
}
 
Example 5
Source File: GlobalUserServiceImpl.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
/**
 * @param data
 * @return
 */
@Override
@Transactional(rollbackFor = Exception.class)
public GlobalUser update(GlobalUserUpdateDTO data) {
    if (StrUtil.isNotBlank(data.getPassword()) || StrUtil.isNotBlank(data.getPassword())) {
        BizAssert.equals(data.getPassword(), data.getConfirmPassword(), "2次输入的密码不一致");
    }

    GlobalUser globalUser = BeanPlusUtil.toBean(data, GlobalUser.class);
    if (StrUtil.isNotBlank(data.getPassword())) {
        String md5Password = SecureUtil.md5(data.getPassword());
        globalUser.setPassword(md5Password);

    }
    updateById(globalUser);
    return globalUser;
}
 
Example 6
Source File: UserServiceImpl.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean updatePassword(UserUpdatePasswordDTO data) {
    BizAssert.equals(data.getConfirmPassword(), data.getPassword(), "密码与确认密码不一致");

    User user = getById(data.getId());
    BizAssert.notNull(user, "用户不存在");
    String oldPassword = SecureUtil.md5(data.getOldPassword());
    BizAssert.equals(user.getPassword(), oldPassword, "旧密码错误");

    User build = User.builder().password(SecureUtil.md5(data.getPassword())).id(data.getId()).build();
    updateById(build);
    return true;
}
 
Example 7
Source File: AdminController.java    From blog-sharon with Apache License 2.0 5 votes vote down vote up
/**
 * 获取一个Token
 *
 * @return JsonResult
 */
@GetMapping(value = "/getToken")
@ResponseBody
public JsonResult getToken() {
    String token = (System.currentTimeMillis() + new Random().nextInt(999999999)) + "";
    return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), SecureUtil.md5(token));
}
 
Example 8
Source File: UserServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 更新用户
 *
 * @param user 用户实体
 * @param id   主键id
 * @return 更新成功 {@code true} 更新失败 {@code false}
 */
@Override
public Boolean update(User user, Long id) {
	User exist = getUser(id);
	if (StrUtil.isNotBlank(user.getPassword())) {
		String rawPass = user.getPassword();
		String salt = IdUtil.simpleUUID();
		String pass = SecureUtil.md5(rawPass + Const.SALT_PREFIX + salt);
		user.setPassword(pass);
		user.setSalt(salt);
	}
	BeanUtil.copyProperties(user, exist, CopyOptions.create().setIgnoreNullValue(true));
	exist.setLastUpdateTime(new DateTime());
	return userDao.update(exist, id) > 0;
}
 
Example 9
Source File: SystemConfigService.java    From zfile with MIT License 5 votes vote down vote up
/**
 * 更新后台账号密码
 *
 * @param   username
 *          用户名
 *
 * @param   password
 *          密码
 */
public void updateUsernameAndPwd(String username, String password) {
    SystemConfig usernameConfig = systemConfigRepository.findByKey(SystemConfigConstant.USERNAME);
    usernameConfig.setValue(username);
    systemConfigRepository.save(usernameConfig);

    String encryptionPassword = SecureUtil.md5(password);
    SystemConfig systemConfig = systemConfigRepository.findByKey(SystemConfigConstant.PASSWORD);
    systemConfig.setValue(encryptionPassword);

    zFileCache.removeConfig();

    systemConfigRepository.save(systemConfig);
}
 
Example 10
Source File: SqlInjectionUtil.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
public static void checkDictTableSign(String dictCode, String sign, HttpServletRequest request) {
	//表字典SQL注入漏洞,签名校验
	String accessToken = request.getHeader("X-Access-Token");
	String signStr = dictCode + SqlInjectionUtil.TABLE_DICT_SIGN_SALT + accessToken;
	String javaSign = SecureUtil.md5(signStr);
	if (!javaSign.equals(sign)) {
		log.error("表字典,SQL注入漏洞签名校验失败 :" + sign + "!=" + javaSign+ ",dictCode=" + dictCode);
		throw new JeecgBootException("无权限访问!");
	}
	log.info(" 表字典,SQL注入漏洞签名校验成功!sign=" + sign + ",dictCode=" + dictCode);
}
 
Example 11
Source File: UserServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 保存用户
 *
 * @param user 用户实体
 * @return 保存成功 {@code true} 保存失败 {@code false}
 */
@Override
public Boolean save(User user) {
	String rawPass = user.getPassword();
	String salt = IdUtil.simpleUUID();
	String pass = SecureUtil.md5(rawPass + Const.SALT_PREFIX + salt);
	user.setPassword(pass);
	user.setSalt(salt);
	return userDao.insert(user) > 0;
}
 
Example 12
Source File: UserServiceImpl.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean updatePassword(UserUpdatePasswordDTO data) {
    BizAssert.equals(data.getConfirmPassword(), data.getPassword(), "密码与确认密码不一致");

    User user = getById(data.getId());
    BizAssert.notNull(user, "用户不存在");
    String oldPassword = SecureUtil.md5(data.getOldPassword());
    BizAssert.equals(user.getPassword(), oldPassword, "旧密码错误");

    User build = User.builder().password(SecureUtil.md5(data.getPassword())).id(data.getId()).build();
    updateById(build);
    return true;
}
 
Example 13
Source File: SqlInjectionUtil.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
public static void checkDictTableSign(String dictCode, String sign, HttpServletRequest request) {
	//表字典SQL注入漏洞,签名校验
	String accessToken = request.getHeader("X-Access-Token");
	String signStr = dictCode + SqlInjectionUtil.TABLE_DICT_SIGN_SALT + accessToken;
	String javaSign = SecureUtil.md5(signStr);
	if (!javaSign.equals(sign)) {
		log.error("表字典,SQL注入漏洞签名校验失败 :" + sign + "!=" + javaSign+ ",dictCode=" + dictCode);
		throw new JeecgBootException("无权限访问!");
	}
	log.info(" 表字典,SQL注入漏洞签名校验成功!sign=" + sign + ",dictCode=" + dictCode);
}
 
Example 14
Source File: UserServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 更新用户
 *
 * @param user 用户实体
 * @param id   主键id
 * @return 更新成功 {@code true} 更新失败 {@code false}
 */
@Override
public Boolean update(User user, Long id) {
	User exist = getUser(id);
	if (StrUtil.isNotBlank(user.getPassword())) {
		String rawPass = user.getPassword();
		String salt = IdUtil.simpleUUID();
		String pass = SecureUtil.md5(rawPass + Const.SALT_PREFIX + salt);
		user.setPassword(pass);
		user.setSalt(salt);
	}
	BeanUtil.copyProperties(user, exist, CopyOptions.create().setIgnoreNullValue(true));
	exist.setLastUpdateTime(new DateTime());
	return userDao.update(exist, id) > 0;
}
 
Example 15
Source File: GitUtil.java    From Jpom with MIT License 5 votes vote down vote up
public static List<String> getBranchList(String url, String userName, String userPwd) throws GitAPIException, IOException {
    //  生成临时路径
    String tempId = SecureUtil.md5(url);
    File file = ConfigBean.getInstance().getTempPath();
    File gitFile = FileUtil.file(file, "gitTemp", tempId);
    List<String> list = branchList(url, gitFile, new UsernamePasswordCredentialsProvider(userName, userPwd));
    if (list.isEmpty()) {
        throw new JpomRuntimeException("该仓库还没有任何分支");
    }
    return list;
}
 
Example 16
Source File: SslContextHelper.java    From redant with Apache License 2.0 5 votes vote down vote up
private static String getKey(String keyPath,String keyPassword){
    if(keyPath==null || keyPath.trim().length()==0 || keyPassword==null || keyPassword.trim().length()==0){
        return null;
    }
    String keyStr = keyPath+"&"+keyPassword;
    return SecureUtil.md5(keyStr);
}
 
Example 17
Source File: AgentExtConfigBean.java    From Jpom with MIT License 5 votes vote down vote up
/**
 * 创建请求对象
 *
 * @param openApi url
 * @return HttpRequest
 * @see ServerOpenApi
 */
public HttpRequest createServerRequest(String openApi) {
    if (StrUtil.isEmpty(getServerUrl())) {
        throw new JpomRuntimeException("请先配置server端url");
    }
    if (StrUtil.isEmpty(getServerToken())) {
        throw new JpomRuntimeException("请先配置server端Token");
    }
    // 加密
    String md5 = SecureUtil.md5(getServerToken());
    md5 = SecureUtil.sha1(md5 + ServerOpenApi.HEAD);
    HttpRequest httpRequest = HttpUtil.createPost(String.format("%s%s", serverUrl, openApi));
    httpRequest.header(ServerOpenApi.HEAD, md5);
    return httpRequest;
}
 
Example 18
Source File: UserServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 保存用户
 *
 * @param user 用户实体
 * @return 保存成功 {@code true} 保存失败 {@code false}
 */
@Override
public Boolean save(User user) {
	String rawPass = user.getPassword();
	String salt = IdUtil.simpleUUID();
	String pass = SecureUtil.md5(rawPass + Const.SALT_PREFIX + salt);
	user.setPassword(pass);
	user.setSalt(salt);
	return userDao.insert(user) > 0;
}
 
Example 19
Source File: Md5PasswordEncoder.java    From zfile with MIT License 4 votes vote down vote up
@Override
public String encode(CharSequence rawPassword) {
    return SecureUtil.md5(rawPassword.toString());
}
 
Example 20
Source File: Node.java    From redant with Apache License 2.0 4 votes vote down vote up
public Node(String host, int port){
    this(SecureUtil.md5(host+"&"+port),host,port);
}