List of usage examples for org.apache.shiro.crypto.hash SimpleHash SimpleHash
public SimpleHash(String algorithmName, Object source, Object salt, int hashIterations) throws CodecException, UnknownAlgorithmException
From source file:cn.com.xl.core.shiro.ShiroKit.java
License:Apache License
/** * shiro?//from www. j a v a 2s .com * * @param ? * @param ?? * @return */ public static String md5(String credentials, String saltSource) { ByteSource salt = new Md5Hash(saltSource); return new SimpleHash(hashAlgorithmName, credentials, salt, hashIterations).toString(); }
From source file:cn.itganhuo.app.service.impl.UserServiceImpl.java
License:Apache License
public boolean updatePasswordByAccount(User user) { String algorithmName = "SHA-512"; String salt1 = user.getAccount(); String salt2 = new SecureRandomNumberGenerator().nextBytes().toHex(); int hashIterations = 2; SimpleHash hash = new SimpleHash(algorithmName, user.getPassword(), salt1.concat(salt2), hashIterations); user.setPassword(hash.toBase64());//from w w w. j a va 2 s. c o m user.setSalt(salt2); return this.userDao.updatePasswordByAccount(user); }
From source file:cn.itganhuo.app.service.impl.UserServiceImpl.java
License:Apache License
@Transactional @Override/* w w w . j av a 2s . co m*/ public RespMsg userRegister(User user, HttpServletRequest request, HttpServletResponse response) { RespMsg respMsg = new RespMsg(); // SQLSQL String tmpAccount = StringEscapeUtils.escapeSql(user.getAccount()); String tmpPassword = StringEscapeUtils.escapeSql(user.getPassword()); user.setAccount(tmpAccount); user.setPassword(tmpPassword); // ??? if (user.getAccount().length() < 6 || user.getAccount().length() > 20) { respMsg.setStatus("1000"); respMsg.setMessage(ConfigPool.getString("respMsg.register.AccountNumberFormatNotLegitimate")); return respMsg; } // ???? if (!StringUtil.ifContainsSpecialStr(user.getAccount())) { respMsg.setStatus("1001"); respMsg.setMessage(ConfigPool.getString("respMsg.register.AccountNumberFormatNotLegitimate")); return respMsg; } // ?? if (user.getPassword().length() < 6 || user.getPassword().length() > 32) { respMsg.setStatus("2000"); respMsg.setMessage(ConfigPool.getString("respMsg.register.PasswordFormatNotLegitimate")); return respMsg; } // ??? String[] s = { "`", "~", "#", "$", "%", "^", "&", "*", "(", ")", "-", "=", "+", "{", "}", "[", "]", "|", "\\", ";", ":", "\'", "\"", "<", ">", ",", "/" }; if (!StringUtil.ifContainsSpecialStr(user.getPassword(), s)) { respMsg.setStatus("2001"); respMsg.setMessage(ConfigPool.getString("respMsg.register.PasswordFormatNotLegitimate")); return respMsg; } // ?????? if (user.getAccount().matches("[\u4e00-\u9fa5]+") || user.getPassword().matches("[\u4e00-\u9fa5]+")) { respMsg.setStatus("3000"); respMsg.setMessage(ConfigPool.getString("respMsg.common.CanNotContainChineseStr")); return respMsg; } // ???? User tmp_user = userDao.loadByAccount(user.getAccount()); if (tmp_user != null) { respMsg.setStatus("1002"); respMsg.setMessage(ConfigPool.getString("respMsg.login.UnknownAccount")); return respMsg; } // ? String algorithmName = "SHA-512"; String salt1 = user.getAccount(); String salt2 = new SecureRandomNumberGenerator().nextBytes().toHex(); int hashIterations = 2; SimpleHash hash = new SimpleHash(algorithmName, user.getPassword(), salt1.concat(salt2), hashIterations); // ?? user.setPassword(hash.toBase64()); user.setSalt(salt2); user.setIsLock(0); user.setPostDate(DateUtil.getNowDateTimeStr(null)); user.setType(1); // ? userDao.insert(user); HttpUtil.setCookie(response, ConstantPool.USER_ACCOUNT_COOKIE_ID, user.getAccount()); return respMsg; }
From source file:cn.itganhuo.app.web.controller.UserController.java
License:Apache License
/** * ????/* w w w .ja v a 2 s . c o m*/ * * @param request * @param response * @return 1000??? * @version 0.0.1-SNAPSHOT * @author ? */ @RequiresAuthentication @RequestMapping(value = "/checkpassword", method = RequestMethod.POST) @ResponseBody public RespMsg checkPassword(HttpServletRequest request, HttpServletResponse response) { RespMsg respMsg = new RespMsg(); String originalanpassword = request.getParameter("originalanpassword"); String account = request.getParameter("account"); if (account != null && !"".equals(account)) { User user = userService.loadByAccount(account); String algorithmName = "SHA-512"; String salt1 = user.getAccount(); String salt2 = user.getSalt(); int hashIterations = 2; SimpleHash hash = new SimpleHash(algorithmName, originalanpassword, salt1 + salt2, hashIterations); if (!hash.toBase64().equals(user.getPassword())) { respMsg.setStatus("1000"); respMsg.setMessage(ConfigPool.getString("respMsg.user.EnterNewPasswordAndOldPasswordSame")); } } return respMsg; }
From source file:cn.mypandora.service.impl.PasswordHelper.java
License:Apache License
/** * ???+?/*from ww w . ja v a 2 s. co m*/ * * @param baseUser */ public void encryptPassword(BaseUser baseUser) { baseUser.setSalt(randomNumberGenerator.nextBytes().toHex()); String newPassword = new SimpleHash(algorithmName, baseUser.getPassword(), ByteSource.Util.bytes(baseUser.getCredentialsSalt()), hashIterations).toHex(); baseUser.setPassword(newPassword); }
From source file:com.adinnet.utils.PasswordUtil.java
License:Apache License
public static String createAdminPwd(String password, String salt) { return new SimpleHash("md5", password, ByteSource.Util.bytes(salt), 2).toHex(); }
From source file:com.adinnet.utils.PasswordUtil.java
License:Apache License
public static String createCustomPwd(String password, String salt) { return new SimpleHash("md5", password, ByteSource.Util.bytes(salt), 1).toHex(); }
From source file:com.appleframework.pay.permission.utils.PasswordHelper.java
License:Apache License
public static void encryptPassword(PmsOperator pmsOperator) { pmsOperator.setsalt(randomNumberGenerator.nextBytes().toHex()); String newPassword = new SimpleHash(algorithmName, pmsOperator.getLoginPwd(), ByteSource.Util.bytes(pmsOperator.getCredentialsSalt()), hashIterations).toHex(); pmsOperator.setLoginPwd(newPassword); }
From source file:com.appleframework.pay.permission.utils.PasswordHelper.java
License:Apache License
/** * ?/*from ww w . jav a2s. c om*/ * * @param loginPwd * ? * @param salt * @return */ public static String getPwd(String loginPwd, String salt) { String newPassword = new SimpleHash(algorithmName, loginPwd, ByteSource.Util.bytes(salt), hashIterations) .toHex(); return newPassword; }
From source file:com.cuisongliu.springboot.shiro.support.password.PasswordHelper.java
License:Open Source License
/** * shiro?//ww w. j ava 2 s .co m * * @param credentials ? * @param saltSource ?? * @return */ public String md5(String credentials, String saltSource) { ByteSource salt = new Md5Hash(saltSource); return new SimpleHash(Md5Hash.ALGORITHM_NAME, credentials, salt, springShiroProperties.getMd5Iterations()) .toString(); }