当前位置: 首页>>代码示例>>Java>>正文


Java MD5Util类代码示例

本文整理汇总了Java中com.zheng.common.util.MD5Util的典型用法代码示例。如果您正苦于以下问题:Java MD5Util类的具体用法?Java MD5Util怎么用?Java MD5Util使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MD5Util类属于com.zheng.common.util包,在下文中一共展示了MD5Util类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import com.zheng.common.util.MD5Util; //导入依赖的package包/类
@ApiOperation(value = "新增用户")
@RequiresPermissions("upms:user:create")
@ResponseBody
@RequestMapping(value = "/create", method = RequestMethod.POST)
public Object create(UpmsUser upmsUser) {
    ComplexResult result = FluentValidator.checkAll()
            .on(upmsUser.getUsername(), new LengthValidator(1, 20, "帐号"))
            .on(upmsUser.getPassword(), new LengthValidator(5, 32, "密码"))
            .on(upmsUser.getRealname(), new NotNullValidator("姓名"))
            .doValidate()
            .result(ResultCollectors.toComplex());
    if (!result.isSuccess()) {
        return new UpmsResult(UpmsResultConstant.INVALID_LENGTH, result.getErrors());
    }
    long time = System.currentTimeMillis();
    String salt = UUID.randomUUID().toString().replaceAll("-", "");
    upmsUser.setSalt(salt);
    upmsUser.setPassword(MD5Util.MD5(upmsUser.getPassword() + upmsUser.getSalt()));
    upmsUser.setCtime(time);
    upmsUser = upmsUserService.createUser(upmsUser);
    if (null == upmsUser) {
        return new UpmsResult(UpmsResultConstant.FAILED, "帐号名已存在!");
    }
    _log.info("新增用户,主键:userId={}", upmsUser.getUserId());
    return new UpmsResult(UpmsResultConstant.SUCCESS, 1);
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:27,代码来源:UpmsUserController.java

示例2: doGetAuthenticationInfo

import com.zheng.common.util.MD5Util; //导入依赖的package包/类
/**
 * 认证:登录时调用
 * @param authenticationToken
 * @return
 * @throws AuthenticationException
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
    String username = (String) authenticationToken.getPrincipal();
    String password = new String((char[]) authenticationToken.getCredentials());
    // client无密认证
    String upmsType = PropertiesFileUtil.getInstance("zheng-upms-client").get("zheng.upms.type");
    if ("client".equals(upmsType)) {
        return new SimpleAuthenticationInfo(username, password, getName());
    }

    // 查询用户信息
    UpmsUser upmsUser = upmsApiService.selectUpmsUserByUsername(username);

    if (null == upmsUser) {
        throw new UnknownAccountException();
    }
    if (!upmsUser.getPassword().equals(MD5Util.MD5(password + upmsUser.getSalt()))) {
        throw new IncorrectCredentialsException();
    }
    if (upmsUser.getLocked() == 1) {
        throw new LockedAccountException();
    }

    return new SimpleAuthenticationInfo(username, password, getName());
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:32,代码来源:UpmsRealm.java

示例3: create

import com.zheng.common.util.MD5Util; //导入依赖的package包/类
@ApiOperation(value = "新增用户")
@RequiresPermissions("upms:user:create")
@ResponseBody
@RequestMapping(value = "/create", method = RequestMethod.POST)
public Object create(UpmsUser upmsUser) {
    ComplexResult result = FluentValidator.checkAll()
            .on(upmsUser.getUsername(), new LengthValidator(1, 20, "帐号"))
            .on(upmsUser.getPassword(), new LengthValidator(5, 32, "密码"))
            .on(upmsUser.getRealname(), new NotNullValidator("姓名"))
            .doValidate()
            .result(ResultCollectors.toComplex());
    if (!result.isSuccess()) {
        return new UpmsResult(UpmsResultConstant.INVALID_LENGTH, result.getErrors());
    }
    long time = System.currentTimeMillis();
    String salt = UUID.randomUUID().toString().replaceAll("-", "");
    upmsUser.setSalt(salt);
    upmsUser.setPassword(MD5Util.md5(upmsUser.getPassword() + upmsUser.getSalt()));
    upmsUser.setCtime(time);
    upmsUser = upmsUserService.createUser(upmsUser);
    if (null == upmsUser) {
        return new UpmsResult(UpmsResultConstant.FAILED, "帐号名已存在!");
    }
    LOGGER.info("新增用户,主键:userId={}", upmsUser.getUserId());
    return new UpmsResult(UpmsResultConstant.SUCCESS, 1);
}
 
开发者ID:ChangyiHuang,项目名称:shuzheng,代码行数:27,代码来源:UpmsUserController.java

示例4: doGetAuthenticationInfo

import com.zheng.common.util.MD5Util; //导入依赖的package包/类
/**
 * 认证:登录时调用
 * @param authenticationToken
 * @return
 * @throws AuthenticationException
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
    String username = (String) authenticationToken.getPrincipal();
    String password = new String((char[]) authenticationToken.getCredentials());
    // client无密认证
    String upmsType = PropertiesFileUtil.getInstance("zheng-upms-client").get("zheng.upms.type");
    if ("client".equals(upmsType)) {
        return new SimpleAuthenticationInfo(username, password, getName());
    }

    // 查询用户信息
    UpmsUser upmsUser = upmsApiService.selectUpmsUserByUsername(username);

    if (null == upmsUser) {
        throw new UnknownAccountException();
    }
    if (!upmsUser.getPassword().equals(MD5Util.md5(password + upmsUser.getSalt()))) {
        throw new IncorrectCredentialsException();
    }
    if (upmsUser.getLocked() == 1) {
        throw new LockedAccountException();
    }

    return new SimpleAuthenticationInfo(username, password, getName());
}
 
开发者ID:ChangyiHuang,项目名称:shuzheng,代码行数:32,代码来源:UpmsRealm.java


注:本文中的com.zheng.common.util.MD5Util类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。