【发布时间】:2017-04-25 12:43:33
【问题描述】:
我正在使用 shiro 作为我的 java 1.8 应用程序的身份验证。我的用户创建将 sha256 和 salt。
Shiro 只会匹配数据库中输入的密码。例如,如果数据库密码是纯文本的并且是“密码”并且我输入了“密码”,它会起作用。
如果我在数据库中加密密码时输入了“密码”,则它不匹配并且会失败。
如何让 shiro 根据输入的内容创建 sha256 和加盐密码,以便密码匹配?
我的用户创建代码
EntityManagerFactory factory =
Persistence.createEntityManagerFactory("e");
EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
com.e.dto.User user = new com.e.dto.User();
DefaultPasswordService a = new DefaultPasswordService();
password = a.encryptPassword(password);
user.setUsername(username);
user.setPassword(password);
em.persist(user);
em.getTransaction().commit();
shiro.ini
jdbcRealm=org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealm.authenticationQuery = SELECT password from user where username = ?
jdbcRealm.userRolesQuery = select role from userroles where userID = (select id FROM user WHERE username = ?)
ds = com.mysql.jdbc.jdbc2.optional.MysqlDataSource
ds.serverName = localhost
ds.user = root
ds.password = password
ds.databaseName = myDatabase
jdbcRealm.dataSource= $ds
credentialsMatcher = org.apache.shiro.authc.credential.HashedCredentialsMatcher
credentialsMatcher.hashAlgorithmName = SHA-256
credentialsMatcher.storedCredentialsHexEncoded = true
credentialsMatcher.hashIterations = 10000
credentialsMatcher.hashSalted = true
新用户密码
$shiro1$SHA-256$500000$xRvz5dByhvAtFG7VHlCjHA==$xxakvEZdBF6cI+UmyR1OY098tAlscOKhpwQuT7THijw=
【问题讨论】:
标签: java security shiro sha256