前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。

1. 正文:

package com.service.impl;import java.util.ArrayList;import java.util.List;import javax.annotation.Resource;import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.apache.shiro.crypto.RandomNumberGenerator;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;import com.entity.AuthAdmin;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.AuthAdminMapper;
import com.service.IAuthAdminService;
import com.service.IAuthRoleService;/*** 用户管理* @author JiangYu*/
@Service
public class AuthAdminServiceImpl implements IAuthAdminService {private RandomNumberGenerator randomNumberGenerator = new SecureRandomNumberGenerator();@Resourceprivate AuthAdminMapper _authAdminMapper;@Resourceprivate IAuthRoleService _authRoleService;// 从配置properties文件中读取以下3项@Value("${password.algorithmName}")private String algorithmName; // 加密方式:md5@Value("${password.hashIterations}")private int hashIterations;   // 次数:2@Value("${init.password}")private String initPwd;       // 初始化密码:adminLogger _logger = Logger.getLogger(AuthAdminServiceImpl.class);//新增用户@Overridepublic void insertAuthAdmin(AuthAdmin authAdmin) throws Exception {if ( StringUtils.isBlank(authAdmin.getAccount())|| StringUtils.isBlank(authAdmin.getRoleIds())) {_logger.error("---------添加用户数据出错-------------");throw new Exception();}// 密码加盐authAdmin.setSalt(randomNumberGenerator.nextBytes().toHex());String newPassword = new SimpleHash(algorithmName,initPwd,ByteSource.Util.bytes(authAdmin.getSalt()),hashIterations).toHex();authAdmin.setPassword(newPassword);authAdmin.setRoleName(_authRoleService.selectRoleNameByIds(authAdmin.getRoleIds()));authAdmin.setLocked("否");_authAdminMapper.insertAuthAdmin(authAdmin);}/*** 修改密码*/@Overridepublic Integer updatePwd(AuthAdmin admin) throws Exception {// 密码加盐admin.setSalt(randomNumberGenerator.nextBytes().toHex());String newPassword = new SimpleHash(algorithmName,admin.getPassword(),ByteSource.Util.bytes(admin.getSalt()),hashIterations).toHex();admin.setPassword(newPassword);Integer resullt  = _authAdminMapper.updateAuthAdmin(admin);return resullt;}... ... private String algorithmName; // 加密方式:md5@Value("${password.hashIterations}")private int hashIterations;   // 次数:2@Value("${init.password}")private String initPwd;       // 初始化密码:adminLogger _logger = Logger.getLogger(AuthAdminServiceImpl.class);//新增用户@Overridepublic void insertAuthAdmin(AuthAdmin authAdmin) throws Exception {if ( StringUtils.isBlank(authAdmin.getAccount())|| StringUtils.isBlank(authAdmin.getRoleIds())) {_logger.error("---------添加用户数据出错-------------");throw new Exception();}// 密码加盐authAdmin.setSalt(randomNumberGenerator.nextBytes().toHex());String newPassword = new SimpleHash(algorithmName,initPwd,ByteSource.Util.bytes(authAdmin.getSalt()),hashIterations).toHex();authAdmin.setPassword(newPassword);authAdmin.setRoleName(_authRoleService.selectRoleNameByIds(authAdmin.getRoleIds()));authAdmin.setLocked("否");_authAdminMapper.insertAuthAdmin(authAdmin);}/*** 修改密码*/@Overridepublic Integer updatePwd(AuthAdmin admin) throws Exception {// 密码加盐admin.setSalt(randomNumberGenerator.nextBytes().toHex());String newPassword = new SimpleHash(algorithmName,admin.getPassword(),ByteSource.Util.bytes(admin.getSalt()),hashIterations).toHex();admin.setPassword(newPassword);Integer resullt  = _authAdminMapper.updateAuthAdmin(admin);return resullt;}... ...

2. 配置文件中配置:

#MD5
password.algorithmName=md5
password.hashIterations=2
#initpwd
init.password=admin

3. 说明:加密工作主要是 对管理员对象admin  的salt属性、password属性赋值就行了。

存入数据库的是这样的值;

shiro管理下MD5加密的使用相关推荐

  1. linux下md5加密(使用openssl库C实现)

    from: http://blog.csdn.net/shahongzhou/article/details/6307972 本文介绍linux c使用openssl/md5.h加密,有两种实现方法. ...

  2. python md5加密_Python MD5加密实例详解

    详解Python MD5加密 Python 3下MD5加密 # 由于MD5模块在python3中被移除 # 在python3中使用hashlib模块进行md5操作 import hashlib # 待 ...

  3. android apk md5加密工具,Android实现简单MD5加密的方法

    本文实例讲述了Android实现简单MD5加密的方法.分享给大家供大家参考,具体如下: 网上关于android下MD5加密的资料很多,但是测试了下总是跟网站的md5加密不一样, 后来才知道是编码方式不 ...

  4. android md5的使用方法,Android实现简单MD5加密的方法

    本文实例讲述了Android实现简单MD5加密的方法.分享给大家供大家参考,具体如下: 网上关于android下MD5加密的资料很多,但是测试了下总是跟网站的md5加密不一样, 后来才知道是编码方式不 ...

  5. shiro配置盐值加密

    shiro配置盐值加密 一:在shiro配置文件ShiroConfig.java中配置密码凭证匹配器 /*** 密码凭证匹配器,作为自定义认证的基础* @return*/@Beanpublic Has ...

  6. Shiro权限框架(4):MD5加密

    MD5加密 shiro有很多加密算法,如md5和sha,而且还支持加盐,使得密码的解析变得更有难度,更好的保障了数据的安全性.首先我们来看看md5算法的各种实现方式: package com.buba ...

  7. 降龙十八掌之 springboot整合shiro(含MD5加密)

    java学习爱好者 2019-05-27 16:21:00 开发环境: 1.mysql - 5.7.21 2.navicat(mysql客户端管理工具) 3.idea 2017 4.jdk9 5.to ...

  8. Shiro的Base64和MD5加密的使用

    场景 Shiro自带Base64和MD5加密. Base64位置: MD5位置: 实现 新建测试类 package com.badao.util;import org.apache.shiro.cod ...

  9. shiro框架采取MD5+salt方式加密密码

    1.Maven配置 <dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-s ...

最新文章

  1. 在安装完成oracle的时候,需要su - oracle,但有时候出现ulimit pize...
  2. Visual Studio开发必备:扩展工具应用
  3. laravel 在nginx服务器上除了首页其余都是404的问题
  4. Bayesian Networks
  5. boost::mp11::mp_replace_if相关用法的测试程序
  6. Drupal 为前台(Front page)页面添加区域(Regions)
  7. Android项目中,在一个数据库里建立多张表
  8. 精通webpack的5大关键点
  9. python索引字符串_Python:通过索引删除子字符串
  10. js实现关于分页的一种实现方式
  11. 程序员之道——编程也是一门艺术
  12. 三星Galaxy note I9220 系统廋身
  13. Android4OpenCV实时人脸检测detectMultiScale报错
  14. 农村常见60种野生中草药
  15. iOS开发:xcode无法选择设备和corner stone如何过滤上传文件
  16. 自然语言处理--Keras 实现LSTM循环神经网络分类 IMDB 电影评论数据集
  17. office2016专业增强版语言包 VOL
  18. 安全合规/法案--32--《儿童个人信息网络保护规定》原文及解读
  19. GSM通话断续问题分析
  20. 控制理论中的几种稳定性

热门文章

  1. Windows高级编程学习笔记(三)
  2. 【CodeForces - 616C】The Labyrinth(bfs,并查集,STLset)
  3. 【2019浙江省赛 - B】Element Swapping(思维,数学)
  4. 【Hihocoder - 1723】子树统计(线性基合并)
  5. Apollo进阶课程㉝丨Apollo ROS原理—2
  6. Linux中软件安装使用的命令是,Linux软件安装命令
  7. 内构函数java_Android JNI参数传递
  8. leetcode197. 上升的温度(SQL)
  9. leetcode45 跳跃游戏II 秒杀所有答案
  10. C++(STL):04---智能指针之weak_ptr