我获得了一个JSP页面,任何人都可以查看页面源并找到用户名和密码。我的任务是使它有点安全。经过一番阅读后,我想我想实现一个SHA-256加密系统,但我不太清楚如何做到这一点。
我应该如何存储哈希密码?我几乎没有任何JSP /安全经验,所以我不完全理解这些步骤。在用户输入密码并使用SHA 256加密后,此字符串是否与文本文件中的字符串进行比较?最好的方法是什么?
在一个JSP文件中完成整个过程与多个文件之间的区别是什么。我注意到有时登录和加密发生在同一个文件中,而其他时候,表单使用其他JSP文件。
答案 0 :(得分:0)
使用spring web mvc + spring安全插件,只需xml和数据库即可提供所需的一切
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/admin*" access="hasAnyRole('ROLE_Admin')" />
<form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/loginfailed" />
<logout logout-success-url="/login" />
</http>
<authentication-manager>
<authentication-provider>
<password-encoder hash="sha256"/>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="
select username,password, enabled
from users where username=?"
authorities-by-username-query="
select u.username, u.authority from users u
where u.username =? "
/>
</authentication-provider>
</authentication-manager>
</beans:beans>