Java Code Examples for org.springframework.util.DigestUtils

The following examples show how to use org.springframework.util.DigestUtils. These examples are extracted from open source projects. 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
@Override
public TbMember addMember(MemberDto memberDto) {

    TbMember tbMember= DtoUtil.MemberDto2Member(memberDto);

    if(getMemberByUsername(tbMember.getUsername())!=null){
        throw new XmallException("用户名已被注册");
    }
    if(getMemberByPhone(tbMember.getPhone())!=null){
        throw new XmallException("手机号已被注册");
    }
    if(getMemberByEmail(tbMember.getEmail())!=null){
        throw new XmallException("邮箱已被注册");
    }

    tbMember.setState(1);
    tbMember.setCreated(new Date());
    tbMember.setUpdated(new Date());
    String md5Pass = DigestUtils.md5DigestAsHex(tbMember.getPassword().getBytes());
    tbMember.setPassword(md5Pass);

    if(tbMemberMapper.insert(tbMember)!=1){
        throw new XmallException("添加用户失败");
    }
    return getMemberByPhone(tbMember.getPhone());
}
 
Example 2
@Override
public TbMember updateMember(Long id,MemberDto memberDto) {

    TbMember tbMember = DtoUtil.MemberDto2Member(memberDto);
    tbMember.setId(id);
    tbMember.setUpdated(new Date());
    TbMember oldMember=getMemberById(id);
    tbMember.setState(oldMember.getState());
    tbMember.setCreated(oldMember.getCreated());
    if(tbMember.getPassword()==null||tbMember.getPassword()==""){
        tbMember.setPassword(oldMember.getPassword());
    }else{
        String md5Pass = DigestUtils.md5DigestAsHex(tbMember.getPassword().getBytes());
        tbMember.setPassword(md5Pass);
    }

    if (tbMemberMapper.updateByPrimaryKey(tbMember) != 1){
        throw new XmallException("更新会员信息失败");
    }
    return getMemberById(id);
}
 
Example 3
@Override
public int register(String userName,String userPwd) {

	TbMember tbMember=new TbMember();
	tbMember.setUsername(userName);

	if(userName.isEmpty()||userPwd.isEmpty()){
		return -1; //用户名密码不能为空
	}
	boolean result = checkData(userName, 1);
	if (!result) {
		return 0; //该用户名已被注册
	}

	//MD5加密
	String md5Pass = DigestUtils.md5DigestAsHex(userPwd.getBytes());
	tbMember.setPassword(md5Pass);
	tbMember.setState(1);
	tbMember.setCreated(new Date());
	tbMember.setUpdated(new Date());

	if(tbMemberMapper.insert(tbMember)!=1){
		throw new XmallException("注册用户失败");
	}
	return 1;
}
 
Example 4
Source Project: spring-analysis-note   Source File: AppCacheManifestTransformer.java    License: MIT License 6 votes vote down vote up
private Mono<? extends Resource> transform(String content, Resource resource,
		ResourceTransformerChain chain, ServerWebExchange exchange) {

	if (!content.startsWith(MANIFEST_HEADER)) {
		if (logger.isTraceEnabled()) {
			logger.trace(exchange.getLogPrefix() +
					"Skipping " + resource + ": Manifest does not start with 'CACHE MANIFEST'");
		}
		return Mono.just(resource);
	}
	return Flux.generate(new LineInfoGenerator(content))
			.concatMap(info -> processLine(info, exchange, resource, chain))
			.reduce(new ByteArrayOutputStream(), (out, line) -> {
				writeToByteArrayOutputStream(out, line + "\n");
				return out;
			})
			.map(out -> {
				String hash = DigestUtils.md5DigestAsHex(out.toByteArray());
				writeToByteArrayOutputStream(out, "\n" + "# Hash: " + hash);
				return new TransformedResource(resource, out.toByteArray());
			});
}
 
Example 5
Source Project: xxl-api   Source File: XxlApiUserController.java    License: GNU General Public License v3.0 6 votes vote down vote up
@RequestMapping("/updatePwd")
@ResponseBody
public ReturnT<String> updatePwd(HttpServletRequest request, String password){

	// new password(md5)
	if (StringTool.isBlank(password)){
		return new ReturnT<String>(ReturnT.FAIL.getCode(), "密码不可为空");
	}
	if (!(password.length()>=4 && password.length()<=100)) {
		return new ReturnT<String>(ReturnT.FAIL.getCode(), "密码长度限制为4~50");
	}
	String md5Password = DigestUtils.md5DigestAsHex(password.getBytes());

	// update pwd
	XxlApiUser loginUser = (XxlApiUser) request.getAttribute(LoginService.LOGIN_IDENTITY);

	XxlApiUser existUser = xxlApiUserDao.findByUserName(loginUser.getUserName());
	existUser.setPassword(md5Password);
	xxlApiUserDao.update(existUser);

	return ReturnT.SUCCESS;
}
 
Example 6
Source Project: xxl-api   Source File: LoginService.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * login
 *
 * @param response
 * @param usernameParam
 * @param passwordParam
 * @param ifRemember
 * @return
 */
public ReturnT<String> login(HttpServletResponse response, String usernameParam, String passwordParam, boolean ifRemember){

    XxlApiUser xxlApiUser = xxlApiUserDao.findByUserName(usernameParam);
    if (xxlApiUser == null) {
        return new ReturnT<String>(500, "账号或密码错误");
    }

    String passwordParamMd5 = DigestUtils.md5DigestAsHex(passwordParam.getBytes());
    if (!xxlApiUser.getPassword().equals(passwordParamMd5)) {
        return new ReturnT<String>(500, "账号或密码错误");
    }

    String loginToken = makeToken(xxlApiUser);

    // do login
    CookieUtil.set(response, LOGIN_IDENTITY, loginToken, ifRemember);
    return ReturnT.SUCCESS;
}
 
Example 7
Source Project: SimpleBBS   Source File: UserController.java    License: Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value = "/register.do", method = RequestMethod.POST)
public String register(User user, Invitecode invitecode, @RequestParam(value = "yzm", required = false) String yzm, HttpSession session) {
    if (user.getUname().length() > 16 || user.getUpwd().length() > 16 || user.getUpwd().length() < 6) {
        return "注册失败:用户名或密码长度必须小于16位";
    }

    if (session.getAttribute("yzm").equals(yzm.toLowerCase())) {
        user.setUpwd(DigestUtils.md5DigestAsHex(user.getUpwd().getBytes()));
        user.setLevel(1);
        user.setUcreatetime(new Date());
        user.setUstate(1);
        try {
            userService.register(user, invitecode);
            return "注册成功";
        } catch (MessageException e) {
            return e.getMessage();
        }
    } else
        return "验证码错误";

}
 
Example 8
Source Project: xxl-conf   Source File: LoginService.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * login
 *
 * @param response
 * @param usernameParam
 * @param passwordParam
 * @param ifRemember
 * @return
 */
public ReturnT<String> login(HttpServletResponse response, String usernameParam, String passwordParam, boolean ifRemember){

    XxlConfUser xxlConfUser = xxlConfUserDao.load(usernameParam);
    if (xxlConfUser == null) {
        return new ReturnT<String>(500, "账号或密码错误");
    }

    String passwordParamMd5 = DigestUtils.md5DigestAsHex(passwordParam.getBytes());
    if (!xxlConfUser.getPassword().equals(passwordParamMd5)) {
        return new ReturnT<String>(500, "账号或密码错误");
    }

    String loginToken = makeToken(xxlConfUser);

    // do login
    CookieUtil.set(response, LOGIN_IDENTITY, loginToken, ifRemember);
    return ReturnT.SUCCESS;
}
 
Example 9
Source Project: yyblog   Source File: ProfileController.java    License: MIT License 6 votes vote down vote up
@PostMapping("/edit")
@ResponseBody
public YYBlogResult edit(String username, String nickname, 
        String password1, String password2, String avatar) {
    if (password1.equals(password2)) {
        UserDO user = new UserDO();
        user.setUsername(username);
        if (!StringUtils.isEmpty(password1)) {
            user.setPassword(DigestUtils.md5DigestAsHex(password1.getBytes()));    
        }
        user.setNickname(nickname);
        user.setAvatar(avatar);
        user.setUpdateTime(new Date());
        return userService.updateByUsername(user);
    }
    return YYBlogResult.build(500, "密码验证不一致,请检查!");
}
 
Example 10
Source Project: xxl-conf   Source File: UserController.java    License: GNU General Public License v3.0 6 votes vote down vote up
@RequestMapping("/updatePwd")
@ResponseBody
public ReturnT<String> updatePwd(HttpServletRequest request, String password){

    // new password(md5)
    if (StringUtils.isBlank(password)){
        return new ReturnT<String>(ReturnT.FAIL.getCode(), "密码不可为空");
    }
    if (!(password.length()>=4 && password.length()<=100)) {
        return new ReturnT<String>(ReturnT.FAIL.getCode(), "密码长度限制为4~50");
    }
    String md5Password = DigestUtils.md5DigestAsHex(password.getBytes());

    // update pwd
    XxlConfUser loginUser = (XxlConfUser) request.getAttribute(LoginService.LOGIN_IDENTITY);

    XxlConfUser existUser = xxlConfUserDao.load(loginUser.getUsername());
    existUser.setPassword(md5Password);
    xxlConfUserDao.update(existUser);

    return ReturnT.SUCCESS;
}
 
Example 11
/**
 * Generates a fingerprint based on the exception and the current timestamp.
 *
 * @param httpError Error event for which fingerprint is generated.
 * @return The generated fingerprint.
 */
@Override
public String generate(@NonNull HttpError httpError) {
    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
        write(outputStream, exceptionName(httpError));
        write(outputStream, System.currentTimeMillis());

        // To ensure that the fingerprint is unique when the same exception is handled
        // at almost the same time in the same JVM instance.
        write(outputStream, System.nanoTime());

        return DigestUtils.md5DigestAsHex(outputStream.toByteArray());
    } catch (Exception e) {
        logger.warn("Failed to generate a fingerprint for {}", httpError);
        return null;
    }
}
 
Example 12
Source Project: notes   Source File: AdminServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public AdminDto addAdmin(AdminDto dto) throws CommonException {

    String password = StringUtils.trimToEmpty(dto.getAdminPassword());
    if (EMPTY.equals(password)){
        throw new CommonException(ERROR_REGISTRYPASSWORD100011);
    }

    String name = StringUtils.trimToEmpty(dto.getAdminName());
    if (EMPTY.equals(name)){
        throw new CommonException(ERROR_REGISTRY_ADMIN_NAME100012);
    }

    String salt = RandomStringUtils.randomNumeric(6);
    dto.setAdminSalt(salt);
    String md5Password = DigestUtils.md5DigestAsHex((password + salt).getBytes());
    dto.setAdminPassword(md5Password);
    int adminId = adminDtoMapper.insert(dto);
    dto.setAdminId(Long.parseLong(String.valueOf(adminId)));
    dto.setAdminSalt(null);
    return dto;
}
 
Example 13
Source Project: lightconf   Source File: UserServiceImpl.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public ResultCode<User> addUser(User confUser) {

    ResultCode<User> resultCode = new ResultCode();

    // valid
    if (StringUtils.isBlank(confUser.getUserName()) || StringUtils.isBlank(confUser.getPassword())) {
        resultCode.setCode(Messages.INPUT_ERROR_CODE);
        resultCode.setMsg(Messages.INPUT_ERROR_MSG);
        return resultCode;
    }
    if (!(confUser.getPassword().length() >= 4 && confUser.getPassword().length() <= 100)) {
        resultCode.setCode(Messages.INPUT_ERROR_CODE);
        resultCode.setMsg(Messages.INPUT_ERROR_MSG);
        return resultCode;
    }

    // passowrd md5
    String md5Password = DigestUtils.md5DigestAsHex(confUser.getPassword().getBytes());
    confUser.setPassword(md5Password);
    userMapper.insert(confUser);
    resultCode.setData(confUser);
    return resultCode;
}
 
Example 14
Source Project: goods-seckill   Source File: LoginServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ResultCode<String> loginUser(String sessionID, SeckillUserEntity user) {
	ResultCode<String> result = new ResultCode<>();

	if (user.getId() == null)
		return result.ERROE("手机号不能为空");
	if (user.getPassword() == null)
		return result.ERROE("密码不能为空");
	
	SeckillUserEntity userEntity = seckillUserEntityMapper.selectByPrimaryKey(user.getId());
	if (userEntity == null)
		return result.ERROE("手机号未注册");
	
	if (!DigestUtils.md5DigestAsHex(user.getPassword().getBytes()).equals(userEntity.getPassword())) {
		return result.ERROE("密码不正确");
	}
	
	RedisUtil.setValue("user_login_" + sessionID, user.getId().toString());

	return result.OK(null);
}
 
Example 15
Source Project: JavaQuarkBBS   Source File: UserController.java    License: Apache License 2.0 6 votes vote down vote up
@ApiOperation("登录接口")
@ApiImplicitParams({
        @ApiImplicitParam(name = "email", value = "用户邮箱",dataType = "String"),
        @ApiImplicitParam(name = "password", value = "用户密码",dataType = "String")
})
@PostMapping("/login")
public QuarkResult Login(String email,String password) {

    QuarkResult result = restProcessor(() -> {
        User loginUser = userService.findByEmail(email);
        if (loginUser == null)
            return QuarkResult.warn("用户邮箱不存在,请重新输入");
        if (!loginUser.getPassword().equals(DigestUtils.md5DigestAsHex(password.getBytes())))
            return QuarkResult.warn("用户密码错误,请重新输入");
        String token = userService.LoginUser(loginUser);
        return QuarkResult.ok(token);
    });
    return result;
}
 
Example 16
Source Project: JavaQuarkBBS   Source File: UserServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void createUser(String email, String username, String password) {
    User user = new User();
    user.setEmail(email);
    user.setUsername(username);
    user.setInitTime(new Date());
    user.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
    repository.save(user);
}
 
Example 17
@Test
  public void mustReturnBinaryBeanQueriedWithMd5Hash() {
    TestBinaryBean binaryBean = new TestBinaryBean();
    byte[] md5Hash = DigestUtils.md5Digest(String.valueOf(System.nanoTime()).getBytes());
    binaryBean.setMd5Hash(md5Hash);
    testBinaryRepository.save(binaryBean);
    TestBinaryBean actualBean = testBinaryRepository.getByMd5Hash(md5Hash);
//    TestBinaryBean actualBean = testBinaryRepository.findByMd5Hash(md5Hash);
//    TestBinaryBean actualBean = testBinaryRepository.queryByMd5Hash(md5Hash);
    Assert.assertNotNull(actualBean);
    Assert.assertEquals(actualBean.getMd5Hash(), binaryBean.getMd5Hash());
  }
 
Example 18
Source Project: spring-analysis-note   Source File: AppCacheManifestTransformer.java    License: MIT License 5 votes vote down vote up
public void add(LineOutput lineOutput) throws IOException {
	this.writer.write(lineOutput.getLine() + "\n");
	byte[] bytes = (lineOutput.getResource() != null ?
			DigestUtils.md5Digest(getResourceBytes(lineOutput.getResource())) :
			lineOutput.getLine().getBytes(DEFAULT_CHARSET));
	this.baos.write(bytes);
}
 
Example 19
Source Project: spring-analysis-note   Source File: ContentVersionStrategy.java    License: MIT License 5 votes vote down vote up
@Override
public String getResourceVersion(Resource resource) {
	try {
		byte[] content = FileCopyUtils.copyToByteArray(resource.getInputStream());
		return DigestUtils.md5DigestAsHex(content);
	}
	catch (IOException ex) {
		throw new IllegalStateException("Failed to calculate hash for " + resource, ex);
	}
}
 
Example 20
Source Project: lams   Source File: ShallowEtagHeaderFilter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate the ETag header value from the given response body byte array.
 * <p>The default implementation generates an MD5 hash.
 * @param inputStream the response body as an InputStream
 * @param isWeak whether the generated ETag should be weak
 * @return the ETag header value
 * @see org.springframework.util.DigestUtils
 */
protected String generateETagHeaderValue(InputStream inputStream, boolean isWeak) throws IOException {
	// length of W/ + 0 + " + 32bits md5 hash + "
	StringBuilder builder = new StringBuilder(37);
	if (isWeak) {
		builder.append("W/");
	}
	builder.append("\"0");
	DigestUtils.appendMd5DigestAsHex(inputStream, builder);
	builder.append('"');
	return builder.toString();
}
 
Example 21
Source Project: spring-analysis-note   Source File: AbstractSockJsService.java    License: MIT License 5 votes vote down vote up
@Override
public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
	if (request.getMethod() != HttpMethod.GET) {
		sendMethodNotAllowed(response, HttpMethod.GET);
		return;
	}

	String content = String.format(IFRAME_CONTENT, getSockJsClientLibraryUrl());
	byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8);
	StringBuilder builder = new StringBuilder("\"0");
	DigestUtils.appendMd5DigestAsHex(contentBytes, builder);
	builder.append('"');
	String etagValue = builder.toString();

	List<String> ifNoneMatch = request.getHeaders().getIfNoneMatch();
	if (!CollectionUtils.isEmpty(ifNoneMatch) && ifNoneMatch.get(0).equals(etagValue)) {
		response.setStatusCode(HttpStatus.NOT_MODIFIED);
		return;
	}

	response.getHeaders().setContentType(new MediaType("text", "html", StandardCharsets.UTF_8));
	response.getHeaders().setContentLength(contentBytes.length);

	// No cache in order to check every time if IFrame are authorized
	addNoCacheHeaders(response);
	response.getHeaders().setETag(etagValue);
	response.getBody().write(contentBytes);
}
 
Example 22
Source Project: spring-analysis-note   Source File: ShallowEtagHeaderFilter.java    License: MIT License 5 votes vote down vote up
/**
 * Generate the ETag header value from the given response body byte array.
 * <p>The default implementation generates an MD5 hash.
 * @param inputStream the response body as an InputStream
 * @param isWeak whether the generated ETag should be weak
 * @return the ETag header value
 * @see org.springframework.util.DigestUtils
 */
protected String generateETagHeaderValue(InputStream inputStream, boolean isWeak) throws IOException {
	// length of W/ + " + 0 + 32bits md5 hash + "
	StringBuilder builder = new StringBuilder(37);
	if (isWeak) {
		builder.append("W/");
	}
	builder.append("\"0");
	DigestUtils.appendMd5DigestAsHex(inputStream, builder);
	builder.append('"');
	return builder.toString();
}
 
Example 23
Source Project: learning-taotaoMall   Source File: UserServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 用户登录
 * <p>Title: userLogin</p>
 * <p>Description: </p>
 * @param username
 * @param password
 * @param request
 *@param response @return
 */
public TaotaoResult userLogin(String username, String password, HttpServletRequest request, HttpServletResponse response) {

	TbUserExample example = new TbUserExample();
	TbUserExample.Criteria criteria = example.createCriteria();
	criteria.andUsernameEqualTo(username);
	List<TbUser> list = userMapper.selectByExample(example);
	//如果没有此用户名
	if (list.size() == 0) {
		return TaotaoResult.build(400, "用户名或密码错误");
	}
	TbUser user = list.get(0);
	//比对密码
	if (!DigestUtils.md5DigestAsHex((salt + password).getBytes()).equals(user.getPassword())) {
		return TaotaoResult.build(400, "用户名或密码错误");
	}
	//生成token
	String token = UUID.randomUUID().toString().replace("-", "");
	//保存用户之前,把用户对象中的密码清空。
	user.setPassword(null);
	//把用户信息写入redis
	jedisClient.set(REDIS_KEY_STRING_USER_LOGIN + ":" + token, JsonUtils.objectToJson(user));
	//设置session的过期时间
	jedisClient.expire(REDIS_KEY_STRING_USER_LOGIN + ":" + token, REDIS_KEY_STRING_USER_LOGIN_EXPIRE);
	//返回token
	CookieUtils.setCookie(request, response, "TT_TOKEN", token);
	return TaotaoResult.ok(token);
}
 
Example 24
Source Project: mPaaS   Source File: DesignElementApi.java    License: Apache License 2.0 5 votes vote down vote up
/** 计算MD5 */
private String buildMd5(String content) {
	String md5 = DigestUtils.md5DigestAsHex(
			content.getBytes(StandardCharsets.UTF_8));
	return StringHelper.join(md5,
			Integer.toHexString(content.hashCode()), ':',
			Integer.toHexString(content.length()));
}
 
Example 25
Source Project: bird-java   Source File: SignatureInfo.java    License: MIT License 5 votes vote down vote up
/**
 * 默认的签名验证方法
 *
 * sign = md5(nonce + timestamp + base64(param))
 *
 * @return true or false
 */
Boolean checkSignature(){
    String origin = this.nonce + this.timestamp;
    if(StringUtils.isNotBlank(this.params)){
        origin = origin + Base64.getEncoder().encodeToString(this.params.getBytes(Charset.forName("utf-8")));
    }
    String signature = DigestUtils.md5DigestAsHex(origin.getBytes(Charset.forName("utf-8")));
    return signature.equals(this.sign);
}
 
Example 26
Source Project: xxl-conf   Source File: UserController.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * update
 *
 * @return
 */
@RequestMapping("/update")
@PermessionLimit(adminuser = true)
@ResponseBody
public ReturnT<String> update(HttpServletRequest request, XxlConfUser xxlConfUser){

    XxlConfUser loginUser = (XxlConfUser) request.getAttribute(LoginService.LOGIN_IDENTITY);
    if (loginUser.getUsername().equals(xxlConfUser.getUsername())) {
        return new ReturnT<String>(ReturnT.FAIL.getCode(), "禁止操作当前登录账号");
    }

    // valid
    if (StringUtils.isBlank(xxlConfUser.getUsername())){
        return new ReturnT<String>(ReturnT.FAIL.getCode(), "用户名不可为空");
    }

    XxlConfUser existUser = xxlConfUserDao.load(xxlConfUser.getUsername());
    if (existUser == null) {
        return new ReturnT<String>(ReturnT.FAIL.getCode(), "用户名非法");
    }

    if (StringUtils.isNotBlank(xxlConfUser.getPassword())) {
        if (!(xxlConfUser.getPassword().length()>=4 && xxlConfUser.getPassword().length()<=50)) {
            return new ReturnT<String>(ReturnT.FAIL.getCode(), "密码长度限制为4~50");
        }
        // passowrd md5
        String md5Password = DigestUtils.md5DigestAsHex(xxlConfUser.getPassword().getBytes());
        existUser.setPassword(md5Password);
    }
    existUser.setPermission(xxlConfUser.getPermission());

    int ret = xxlConfUserDao.update(existUser);
    return ret>0? ReturnT.SUCCESS: ReturnT.FAIL;
}
 
Example 27
Source Project: yfshop   Source File: AdminController.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 保存管理员
 *
 * @return
 */
@RequestMapping(method = RequestMethod.POST)
public BaseResult save(
        @RequestParam(required = true) String tbSysUserJson,
        @RequestParam(required = true) String optsBy
) {
    int result = 0;

    TbSysUser tbSysUser = null;
    try {
        tbSysUser = MapperUtils.json2pojo(tbSysUserJson, TbSysUser.class);
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (tbSysUser != null) {
        // 密码加密
        String password = DigestUtils.md5DigestAsHex(tbSysUser.getPassword().getBytes());
        tbSysUser.setPassword(password);

        // 新增用户
        if (StringUtils.isBlank(tbSysUser.getUserCode())) {
            tbSysUser.setUserCode(UUID.randomUUID().toString());
            result = adminService.insert(tbSysUser, optsBy);
        }

        // 修改用户
        else {
            result = adminService.update(tbSysUser, optsBy);
        }

        // 最少有一行数据受影响
        if (result > 0) {
            return BaseResult.ok("保存管理员成功");
        }
    }

    return BaseResult.ok("保存管理员失败");
}
 
Example 28
Source Project: mPass   Source File: DesignElementApi.java    License: Apache License 2.0 5 votes vote down vote up
/** 计算MD5 */
private String buildMd5(String content) {
	String md5 = DigestUtils.md5DigestAsHex(
			content.getBytes(StandardCharsets.UTF_8));
	return StringHelper.join(md5,
			Integer.toHexString(content.hashCode()), ':',
			Integer.toHexString(content.length()));
}
 
Example 29
@Override
public void afterPropertiesSet() throws Exception {

    // valid
    if (username==null || username.trim().length()==0 || password==null || password.trim().length()==0) {
        throw new RuntimeException("权限账号密码不可为空");
    }

    // login token
    String tokenTmp = DigestUtils.md5DigestAsHex(String.valueOf(username + "_" + password).getBytes());		//.getBytes("UTF-8")
    tokenTmp = new BigInteger(1, tokenTmp.getBytes()).toString(16);

    LOGIN_IDENTITY_TOKEN = tokenTmp;
}
 
Example 30
public static boolean login(HttpServletResponse response, String username, String password, boolean ifRemember){

    	// login token
		String tokenTmp = DigestUtils.md5DigestAsHex(String.valueOf(username + "_" + password).getBytes());
		tokenTmp = new BigInteger(1, tokenTmp.getBytes()).toString(16);

		if (!getLoginIdentityToken().equals(tokenTmp)){
			return false;
		}

		// do login
		CookieUtil.set(response, LOGIN_IDENTITY_KEY, getLoginIdentityToken(), ifRemember);
		return true;
	}