首先寫乙個md5加密的程式(可以知道密碼加密後的字串 模擬以後從資料庫中取加密的字串)
package com.mo.authentication;
import org.apache.shiro.crypto.hash.md5hash;
import org.apache.shiro.crypto.hash.******hash;
public class md5test
}
得到密碼為123,鹽為abc,雜湊次數為2次的,加密後的字串-->b106dc6352e5ec1f8aafd8c406d34d92
寫乙個realm,將上面得到加密後的字串,加入到下面,模擬從資料庫中取得
package com.mo.shiro.realm;
import org.apache.shiro.authc.authenticationexception;
import org.apache.shiro.authc.authenticationinfo;
import org.apache.shiro.authc.authenticationtoken;
import org.apache.shiro.authc.******authenticationinfo;
import org.apache.shiro.authz.authorizationinfo;
import org.apache.shiro.realm.authorizingrealm;
import org.apache.shiro.subject.principalcollection;
import org.apache.shiro.util.bytesource;
/** *
* 這是乙個realm
* */
public class customrealmmd5 extends authorizingrealm
//認證
protected authenticationinfo dogetauthenticationinfo(
authenticationtoken token) throws authenticationexception
//授權
protected authorizationinfo dogetauthorizationinfo(principalcollection principals)
}
在realm中配置憑證匹配器
[main]
#定義憑證匹配器
credentialsmatcher=org.apache.shiro.authc.credential.hashedcredentialsmatcher
#定義雜湊演算法
credentialsmatcher.hashalgorithmname=md5
#定義雜湊次數
credentialsmatcher.ha****erations=2
#將憑證匹配器設定到realm中
customrealm=com.mo.shiro.realm.customrealmmd5
customrealm.credentialsmatcher=$credentialsmatcher
securitymanager.realms=$customrealm
測試類
@test
public void test2() catch (authenticationexception e)
//檢視認證是否通過,返回的是乙個boolean資料型別
boolean authenticated = subject.isauthenticated();
system.out.println(authenticated);
}
MD5加密實現
author archersc jlu namespace encrpytion include md5.h include include author archersc jlu namespace encrpytion void md5 ff unsigned int a,unsigned in...
MD5加強加密實現
我們主要模擬使用者的註冊和登入加密傳輸密碼部分 註冊 使用者將明文密碼上傳到伺服器,經由伺服器轉換後,傳給前台乙個加密後的md5值 登入 使用者將加密過的密碼字串在指定位置新增自定義的字元,傳送給後台,後台再次在某個位置,加入自定義字元,返回給前台,使用者使用兩次打亂過的字串密碼進行登入。後台接收到...
雜湊加密 MD5原理
md5是一種雜湊演算法,它輸入任意長度的原文,通過乙個雜湊演算法,會得到固定長度128位 16位元組 的雜湊值。由於修改原文一點資料,獲得的雜湊值完全不同,常常用在放置資料篡改,數字簽名,以及如linux登入密碼儲存的安全認證中 typedef struct md5 cont md5 以512位 6...