本文整理汇总了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);
}
示例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());
}
示例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);
}
示例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());
}