shiro管理下MD5加密的使用

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

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属性赋值就行了。

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

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/451886.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

BZOJ2425:[HAOI2010]计数——题解

https://www.lydsy.com/JudgeOnline/problem.php?id2425 https://www.luogu.org/problemnew/show/P2518 你有一组非零数字(不一定唯一),你可以在其中插入任意个0,这样就可以产生无限个数。比如说给定{1,2},那么可以生成数字12,21…

java继承的问题

一个父类对象变量可以引用该父类的任何一个子类的对象。 但是子类是不能引用父类对象的,这违反类 is-a的规则。

用 @Value(“${xxxx}“)注解从配置文件读取值的用法

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。 1. 用法: 从配置properties文件中读取init.password 的值。 Value("${init.password}")private String initPwd…

scanf 输入加逗号(或者不加逗号)出现的异常及解决方案

我们在写 C 语言代码通常 scanf 的格式控制部分都有两种习惯&#xff0c;加逗号与不加逗号&#xff0c;而这两种情况都会因为我们的不同输入习惯产生一定的问题&#xff0c;这里给出另一种方法。 1、不加逗号 1 #include<stdio.h>2 3 #define SWAP(a, b) aa^b;ba^b;aa^b;…

ant介绍

一般情况下&#xff0c;大多数软件公司做开发的时候都不用myeclipse开发&#xff0c;这是利用ant部署就给我们带来极大的方便&#xff0c;它先将你的project打包成war包&#xff0c;然后部署到指定的服务器中。Ant的概念 当一个代码项目大了以后&#xff0c;每次重新编译&…

IT大牛说的话,不得不记

编程经典语录收集 01. Walking on water and developing software from a specification are easy if both are frozen. – Edward V Berard 在水中行走&#xff0c;和根据一份需求开发软件一样&#xff0c;如果它们都“冻”住了&#xff0c;那就容易了。—— 爱德华贝拉尔德 0…

Showdoc 搭建项目 API 文档系统

showdoc 是 PHP 开发的一款 api 文档系统&#xff0c;因此所需环境和普通 PHP 项目一致 准备环境&#xff1a;php nginxcomposer //注意更换国内镜像&#xff0c;否则速度会很慢&#xff0c;甚至失败 创建项目 composer create-project showdoc/showdoc 配置 showdoc 写权限 ch…

树链剖分入门

这几天学了一个树链剖分&#xff0c;觉得还不是很难&#xff0c;这里我试着讲一讲吧。 首先&#xff0c;我认为树链剖分是把在树上一个节点一个节点的走改为按照某种规则跳&#xff0c;从而降低了时间复杂度。 那这是什么规则呢&#xff1f; 首先我们得知道什么是重链&#xff…

分页插件pageHelpler的使用(ssm框架中)服务器端分页

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 1. maven依赖&#xff1a; <!-- 分页插件 --><dependency><groupId>com.github.pagehelper</groupId><arti…

cvs

cvs 是一个C/S系统&#xff0c;是一个常用的代码版本控制软件。主要在 开源软件 管理中使用。与它相类似的代码 版本控制软件 有 subversion 。多个开发人员通过一个中心版本控制系统来记录文件版本 &#xff0c;从而达到保证文件同步的目的。CVS版本控制系统是一种GNU软件包&a…

学成在线--23.课程图片管理(上传图片)

文章目录一. 需求分析1). 需求分析2). 图片上传流程二. 创建文件系统服务工程1). 工程目录结构2). 项目依赖pom.xml3). 配置文件application.yml三. 后端开发1. 模型类1). 模型类2). Collection2. Api接口3. Dao4. Service5. Controller6. 测试四. 前端开发1. 需求2. 页面1). T…

13个超棒的代码资源网站推荐

很多开发者都有过网站开发的经历&#xff0c;大家使用CSS、HTML以及JavaScript等技术来完成这一工作。但想必大家也知道&#xff0c;网站开发是一个很耗费时间的工作。你可能需要花费大量的时间在一些网站上寻找解决问题的代码段。这的确很耗费时间&#xff0c;但却几乎又是不可…

BZOJ.3052.[WC2013]糖果公园(树上莫队 带修改莫队)

题目链接 BZOJ 当然哪都能交(都比在BZOJ交好)&#xff0c;比如UOJ #58 //67376kb 27280ms //树上莫队带修改莫队 模板题 #include <cmath> #include <cstdio> #include <cctype> #include <cstring> #include <algorithm> //#define gc() get…

Jquery Datatable的使用样例(ssm+bootstrsp框架下)服务器端分页

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 效果&#xff1a; 我这个表格数据 比较少没有第2页 有多例多页的效果&#xff08;带滚动条和翻页&#xff09;&#xff1a; 1. jsp页面…

Hadoop集群(四) Hadoop升级

Hadoop前面安装的集群是2.6版本&#xff0c;现在升级到2.7版本。 注意&#xff0c;这个集群上有运行Hbase&#xff0c;所以&#xff0c;升级前后&#xff0c;需要启停Hbase。 更多安装步骤&#xff0c;请参考&#xff1a; Hadoop集群(一) Zookeeper搭建 Hadoop集群(二) HDFS搭建…

学成在线--24.课程图片管理(保存课程图片)

文章目录一. 需求分析二. 服务端开发1. 模型类2. API3. Dao4. Service5. Controller三. 前端开发1. API2. 页面1). 添加上传成功的钩子 :on-success"handleSuccess"2). 在钩子方法 中保存课程图片信息一. 需求分析 图片上传到文件系统后&#xff0c;其它子系统如果想…

从任意网页上摘取酷炫Jquery效果为自己使用的方法

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 1. 用的chrome 浏览器 2. 随意百度一个漂亮的jquery效果 比如我找到一个可以旋转的多面体效果 3. 再F12选 Resources到如下界面&…

shell基础05 处理用户输入

1. 命令行参数------类似javac 参数1 参数2 类似Java中编译的javac parm1....。在shell中&#xff0c;参数与参数之间用空格隔开。采用位置参数来识别对应的参数值&#xff1a;$0是程序名&#xff0c;$1是第一个参数&#xff0c;以此类推&#xff0c;知道第9个参数$9。对于大…