Struts2:如何存储安全的用户名和密码 [英] Struts2: how to store safety username and password from action to action

查看:134
本文介绍了Struts2:如何存储安全的用户名和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在登录页面中,我通过用户名和密码(从jsp页面获取)登录,然后检查LDAP,如果凭据正确,则继续浏览到其他页面。

In my login page I log in through username and password (that I get from a jsp page), then I check LDAP and if the credentials are correct, then I continue the browsing to other pages.

我想存储用户名和密码,因为在接下来的某些页面中,我可能需要它们来制作其他东西。

I would like to store somewhere username and password, because in some next pages, I may need them to make other stuff.

I本来打算将它们存储在会话中,但是我担心这会带来安全问题。我错了吗?也许最好将它们存储在数据库中,并在需要时每次查询数据库,并在会话中仅存储一个指向数据库记录的ID? (这可以,但是可能存在更快,更好的方法)

I was thinking to store them in the session, but I'm scared that this can bring to security issue. Am I wrong? Maybe is it better to store them in the DB and query the DB the every times that I need them, and storing in the session just an ID that point to a DB record? (this could be ok, but maybe exist faster and better ways)

哪种是最好的存储方式?

Which is the best way to store them from action to action?

推荐答案

不同位置的不同密码



您应为Web应用程序和LDAP使用不同的密码。像现在一样,发现LDAP密码的攻击者会自动访问您的应用程序,反之亦然。

Different passwords for different places

You should use different passwords for your web application and LDAP. Like now, an attacker that discovers the LDAP password automatically gains access to your application, and viceversa.

强制用户(通常很容易在任何地方都使用相同的密码,因为这样很容易请记住)在您的Web应用程序中创建新密码时,通过检查密码是否相等(与LDAP相对)来选择其他密码。

Force the user (that usually wants the same password everywhere because it's easy to remember) to choose a different password by checking its equality (against the LDAP one) when creating a new password in your webapp.

您不应将用户密码保存在任何地方,因为具有数据库访问权限的任何人都可以检索所有密码。

You should not save users passwords anywhere, because anyone with database access would be able to retrieve all the passwords.

正确的密码go不是 加密 ,而是 单向散列 (最好使用,以防止彩虹表攻击):

The correct way to go is not encryption, but one-way hashing (better with Salt, to prevent Rainbow Tables attacks):


  1. 在用户创建密码时将其哈希,然后将结果保存在db上。

  2. 当用户登录时,对输入的密码进行哈希处理,然后对照数据库中的哈希值检查生成的哈希值。

  3. 如果用户忘记了密码,请重置密码并要求他选择一个新密码。

在Java中,最好的实现之一是基于 jBCrypt = http://en.wikipedia.org/wiki/Bcrypt rel = nofollow noreferrer> BCrypt 。

In Java one of the best implementations out there is jBCrypt, based on BCrypt.

因为出于各种原因它更安全 乔恩·斯基特说了:)

这篇关于Struts2:如何存储安全的用户名和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆