English 中文(简体)
1. 将用户密码从db记录中匹配
原标题:matching user s password from record in db

In my web app which uses servlets and hibernate. I need to authenticate a Customer who enters a password.

If he is already in database, I need to check if his password matches that of the record in db.For a new Customer, I want to take a password and create a record for him. I tried to do it this way for the scenarios.

现有客户进入电子邮件 地址和密码

String email = req.getParameter("emailAddress");
String password = req.getParameter("password");
Customer cust = dao.findByEmailAddress(email);

现在,我如何检查这个黄色物体是否与密码有关,是否与用户的相匹配? 曼宁的藏书实例将密码作为客户阶层的长处。 这是一种好的想法吗? 如何储存在数据库中?

在使用秘密时,如何处理这一问题? 我听到有人提到,传闻像过去一样。 但我不相信我能怎样做。

Can someone tell me how I can tackle this?

最佳回答

你们必须决定如何储存密码。 如果你把他们作为解放实体储存起来,他们将储存在数据库中,内容明确。 任何人都可以查阅数据库。 本案的评议包括将发送的密码与数据库中的密码进行比较。

There are two other possibilities

The first one consists in encrypting them with a secret key before storing them in database. But this secret key will have to be stored somewhere in order for your application to decrypt them and compare the decrypted password with the one sent by the user. But it could at least reduce the visibility of the password only to the persons having acces to the application deployment directory. Authenticating in this case consists in decrypting the password stored in database with the secret key, and compare it with the password sent by the user. If they are equal, then the user sent the correct password.

最后一种可能性是使用单向散射算法(例如SHA-1,又称电文摘要算法)。 这样,就不需要秘密钥匙,任何人都很难(现在:几乎不可能)查阅密码(如果密码被打盐的话)。 这一解决办法的缺点是,如果用户放松其密码,那么你就能够寄出他。 唯一的可能性是使他重新获得新的价值,向用户发出这一新的密码,并请他选择新的密码。 在此情况下,对用户进行认证,包括打上他发出的密码,并与数据库中储存的散射器进行比较。

http://en.wikipedia.org/wiki/Salt_(加密技术” rel=“nofollow”>http://en.wikipedia.org/wiki/Salt_(加密技术),以提供更详细的解释。

问题回答

通常密码储存在数据库中,如果输入密码相匹配,则你必须加密。

String passwordEncrypted = encrypt(password);

where encrypt is your function that crypt the password (you can try with MD5 or SHA-1, for example).

在您检索到的标码<>cust后,您可核查

if (cust.getPassword().equals(passwordEncrypted)) {
    // login successfull code
} else {
    // login failed code
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签