是的,虽然足够,但HashedCredentialsMatcher有点旧。您可能会发现Shiro较新的PasswordMatcher易于使用。您可以很容易地配置其内部PasswordService:
[main]passwordService = org.apache.shiro.authc.credential.DefaultPasswordService#configure the passwordService to use the settings you desire#...passwordMatcher = org.apache.shiro.authc.credential.PasswordMatcherpasswordMatcher.passwordService = $passwordService#...# Finally, set the matcher on a realm that requires password matching for account authentication:myRealm = ...myRealm.credentialsMatcher = $passwordMatcher
PasswordService创建帐户或更新帐户密码时,可以在应用程序中使用的实例创建密码哈希:
String submittedPlaintextPassword = ...String encryptedValue = passwordService.encryptPassword(submittedPlaintextPassword);...userAccount.setPassword(encryptedValue);userAccount.save(); //create or update to your data store
只需确保配置的passwordService
shiro.ini与
passwordService应用程序代码中使用的配置相同即可。



