Java Code Examples for com.jfinal.kit.HashKit#sha256()
The following examples show how to use
com.jfinal.kit.HashKit#sha256() .
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: UserServiceProvider.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Ret doValidateUserPwd(User user, String pwd) { if (user == null) { return Ret.fail("message", "用户名或密码不正确"); } if (user.isStatusLocked()) { return Ret.fail("message", "该账号已被冻结"); } String salt = user.getSalt(); String hashedPass = HashKit.sha256(salt + pwd); // 未通过密码验证 if (!user.getPassword().equals(hashedPass)) { return Ret.fail("message", "用户名或密码不正确"); } // 更新用户的登录时间 updateUserLoginedDate(user); return Ret.ok().set("user_id", user.getId()); }
Example 2
Source File: _UserController.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@EmptyValidate({ @Form(name = "newPwd", message = "新密码不能为空"), @Form(name = "confirmPwd", message = "确认密码不能为空") }) public void doUpdatePwd(long uid, String oldPwd, String newPwd, String confirmPwd) { User user = userService.findById(uid); if (user == null) { renderJson(Ret.fail().set("message", "该用户不存在")); return; } //超级管理员可以修改任何人的密码 if (!roleService.isSupperAdmin(getLoginedUser().getId())) { if (StrUtil.isBlank(oldPwd)) { renderJson(Ret.fail().set("message", "旧密码不能为空")); return; } if (userService.doValidateUserPwd(user, oldPwd).isFail()) { renderJson(Ret.fail().set("message", "密码错误")); return; } } if (newPwd.equals(confirmPwd) == false) { renderJson(Ret.fail().set("message", "两次出入密码不一致")); return; } String salt = user.getSalt(); String hashedPass = HashKit.sha256(salt + newPwd); user.setPassword(hashedPass); userService.update(user); renderOkJson(); }
Example 3
Source File: UserCenterController.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@EmptyValidate({ @Form(name = "oldPwd", message = "旧不能为空"), @Form(name = "newPwd", message = "新密码不能为空"), @Form(name = "confirmPwd", message = "确认密码不能为空") }) public void doUpdatePwd(String oldPwd, String newPwd, String confirmPwd) { User user = getLoginedUser(); if (userService.doValidateUserPwd(user, oldPwd).isFail()) { renderJson(Ret.fail().set("message", "密码错误")); return; } if (newPwd.equals(confirmPwd) == false) { renderJson(Ret.fail().set("message", "两次出入密码不一致")); return; } String salt = user.getSalt(); String hashedPass = HashKit.sha256(salt + newPwd); user.setPassword(hashedPass); userService.update(user); renderOkJson(); }
Example 4
Source File: UserPwdGenerate.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void generate() { String pwd = "123456"; String salt = HashKit.generateSaltForSha256(); String hashedPwd = HashKit.sha256(salt + pwd); System.out.println("login pwd : " + pwd); System.out.println("salt : " + salt); System.out.println("hashed pwd : " + hashedPwd); }
Example 5
Source File: QCloudSmsSender.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean send(SmsMessage sms) { String app_key = JPressOptions.get(JPressConsts.OPTION_CONNECTION_SMS_APPID); String app_secret = JPressOptions.get(JPressConsts.OPTION_CONNECTION_SMS_APPSECRET); String random = new Random().nextInt(1000000) + ""; String time = System.currentTimeMillis() / 1000 + ""; String srcStr = "appkey=" + app_secret + "&random=" + random + "&time=" + time + "&mobile=" + sms.getMobile(); String sig = HashKit.sha256(srcStr); boolean hasCode = StrUtil.isNotBlank(sms.getCode()); String postContent = (hasCode ? SMS_JSON.replace("{code}", sms.getCode()) : SMS_NO_CODE_JSON) .replace("{sig}", sig) .replace("{sign}", sms.getSign()) .replace("{mobile}", sms.getMobile()) .replace("{time}", time) .replace("{tpl_id}", sms.getTemplate()); String url = "https://yun.tim.qq.com/v5/tlssmssvr/sendsms?sdkappid=" + app_key + "&random=" + random; String content = HttpUtil.httpPost(url, postContent); if (StrUtil.isBlank(content)) { return false; } JSONObject resultJson = JSON.parseObject(content); Integer result = resultJson.getInteger("result"); if (result != null && result == 0) { return true; } else { LogKit.error("qcloud sms send error : " + content); return false; } }
Example 6
Source File: _UserController.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
/** * 新增用户 */ public void doAdd() { String pwd = getPara("newPwd"); String confirmPwd = getPara("confirmPwd"); User user = getBean(User.class); if (StrUtil.isBlank(pwd)) { renderJson(Ret.fail().set("message", "密码不能为空").set("errorCode", 3)); return; } if (StrUtil.isBlank(confirmPwd)) { renderJson(Ret.fail().set("message", "确认密码不能为空").set("errorCode", 4)); return; } if (pwd.equals(confirmPwd) == false) { renderJson(Ret.fail().set("message", "两次输入密码不一致").set("errorCode", 5)); return; } User dbUser = userService.findFistByUsername(user.getUsername()); if (dbUser != null) { renderJson(Ret.fail().set("message", "该用户名已经存在").set("errorCode", 10)); return; } if (StrUtil.isNotBlank(user.getEmail())) { dbUser = userService.findFistByEmail(user.getEmail()); if (dbUser != null) { renderJson(Ret.fail().set("message", "邮箱已经存在了").set("errorCode", 11)); return; } } String salt = HashKit.generateSaltForSha256(); String hashedPass = HashKit.sha256(salt + pwd); user.setSalt(salt); user.setPassword(hashedPass); user.setCreated(new Date()); user.setStatus(User.STATUS_OK); user.setCreateSource(User.SOURCE_ADMIN_CREATE); userService.save(user); renderOkJson(); }
Example 7
Source File: InstallController.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
/** * 初始化第一个用户 * * @param username * @param pwd */ private void initFirstUser(String username, String pwd) { if (StrUtil.isBlank(username) || StrUtil.isBlank(pwd)) { return; } UserService userService = Aop.get(UserService.class); User user = userService.findById(1L); if (user == null) { user = new User(); user.setNickname(username); user.setRealname(username); user.setCreateSource(User.SOURCE_WEB_REGISTER); user.setCreated(new Date()); user.setActivated(new Date()); } String salt = HashKit.generateSaltForSha256(); String hashedPass = HashKit.sha256(salt + pwd); user.setSalt(salt); user.setPassword(hashedPass); user.setUsername(username); if (StrUtil.isEmail(username)) { user.setEmail(username.toLowerCase()); } user.setStatus(User.STATUS_OK); userService.saveOrUpdate(user); RoleService roleService = Aop.get(RoleService.class); Role role = roleService.findById(1L); if (role == null) { role = new Role(); role.setCreated(new Date()); } role.setName("默认角色"); role.setDescription("这个是系统自动创建的默认角色"); role.setFlag(Role.ADMIN_FLAG); role.setModified(new Date()); roleService.saveOrUpdate(role); Db.update("DELETE FROM `user_role_mapping` WHERE `user_id` = 1"); Db.update("INSERT INTO `user_role_mapping` (`user_id`, `role_id`) VALUES (1, 1)"); }