日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

shiro管理下MD5加密的使用

發(fā)布時間:2023/12/18 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 shiro管理下MD5加密的使用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

前些天發(fā)現(xiàn)了一個巨牛的人工智能學(xué)習(xí)網(wǎng)站,通俗易懂,風(fēng)趣幽默,忍不住分享一下給大家。點擊跳轉(zhuǎn)到教程。

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; // 次數(shù):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("---------添加用戶數(shù)據(jù)出錯-------------");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; // 次數(shù):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("---------添加用戶數(shù)據(jù)出錯-------------");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屬性賦值就行了。

存入數(shù)據(jù)庫的是這樣的值;

?

?

?

總結(jié)

以上是生活随笔為你收集整理的shiro管理下MD5加密的使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。