在postgres中,只有md5加密,保存密码的最佳方法是什么?

时间:2011-12-28 08:28:44

标签: security postgresql encryption passwords

PostgreSQL只有MD5用于存储密码的加密。

通过阅读黑客日志,似乎单独使用MD5并不是一种非常安全的密码存储方式。

我一直在客户端使用MD5 MD5 - MD5,然后在数据库再次使用MD5 - 但我不知道这更强大。

首先,是否有必要加强存储密码?第二,什么是简单,有效,跨语言的方法?

2 个答案:

答案 0 :(得分:7)

安装pgcrypto扩展程序为您提供了一套可供使用的功能和工具。 其中包括使用bcrypt的能力,这是一种存储密码的好方法。

如果没有在postgres中使用它,你可能会用你使用的语言来考虑它。

相关链接:http://www.postgresql.org/docs/current/static/pgcrypto.html用于postgres-parts,http://codahale.com/how-to-safely-store-a-password/用于激励/解释为什么要使用它。

答案 1 :(得分:2)

无需在数据库中进行散列处理。如果您将盐基于可以在不访问散列密码的情况下确定的用户名之类的东西,那么它在应用程序级别上同样安全:

password_hash = sha256(user_name + password)
user_id = query("SELECT id FROM user WHERE name=? and password_hash=?",
                user_name, password_hash).first()

或者您可以在两个单独的步骤中检查用户名和密码,并使用用户ID作为salt:

user_id, password_hash = query("SELECT id, password_hash FROM user WHERE name=?",
                               user_name).first()
if password_hash != sha256(user_id + password):
    raise Exception("authentication failed")