postgresql Postgres:MD5 密码/普通密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45395538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgres: MD5 Password / Plain password
提问by RalphShnelvar
I'm trying to understand how role passwords are supposed to operate in Postgres.
我试图了解角色密码应该如何在 Postgres 中运行。
https://www.postgresql.org/docs/current/static/sql-createrole.htmlsays for ENCRYPTED / UNENCRYPTED
https://www.postgresql.org/docs/current/static/sql-createrole.html表示 ENCRYPTED / UNENCRYPTED
If the presented password string is already in MD5-encrypted format, then it is stored encrypted as-is,
如果提供的密码字符串已经是 MD5 加密格式,那么它会按原样加密存储,
So my unencrypted password is: MyPassword .
所以我未加密的密码是: MyPassword 。
The MD5 hash of "MyPassword" is 48503dfd58720bd5ff35c102065a52d7
“MyPassword”的 MD5 哈希值为 48503dfd58720bd5ff35c102065a52d7
If I do
如果我做
-- See https://www.postgresql.org/docs/9.6/static/sql-alterrole.html
ALTER ROLE "MeOhMy"
LOGIN
PASSWORD '48503dfd58720bd5ff35c102065a52d7'
;
And then attempt to use "MyPassword" when doing
然后在做的时候尝试使用“MyPassword”
sudo -u postgres psql meohmy -h 127.0.0.1 -d meohmy_development
I, of course, first get prompted for my sudo password and then I get prompted by Postgres "Password for meohmy"
当然,我首先被提示输入我的 sudo 密码,然后我被 Postgres 提示“我的密码”
If I enter MyPassword I get
如果我输入 MyPassword 我得到
FATAL: password authentication failed for user "[email protected]"
If I enter, instead, 48503dfd58720bd5ff35c102065a52d7 then I can sign in.
如果我输入 48503dfd58720bd5ff35c102065a52d7,则我可以登录。
What am I not understanding?
我不明白什么?
回答by RCross
To create an md5 password for PostgreSQL, the formula is:
为PostgreSQL创建md5密码,公式为:
"md5" + md5(password + username)
Here are 3 ways you can create one, where the username is "admin" and the password is "password123"...
这里有 3 种方法可以创建一种,其中用户名是“admin”,密码是“password123”...
Linux:
Linux:
# echo -n "md5"; echo -n "password123admin" | md5sum | awk '{print }'
md53f84a3c26198d9b94054ca7a3839366d
NOTE: The -n is critical to avoid including the newline character in your hash!
注意:-n 对于避免在散列中包含换行符至关重要!
MacOS:
苹果系统:
? echo -n "md5"; md5 -qs "password123admin"
md53f84a3c26198d9b94054ca7a3839366d
Python 2:
蟒蛇2:
>>> import hashlib
>>> print("md5" + hashlib.md5("password123" + "admin").hexdigest())
md53f84a3c26198d9b94054ca7a3839366d
Python 3:
蟒蛇3:
as above, but use binary strings
同上,但使用二进制字符串
print("md5" + hashlib.md5(b"password123" + b"admin").hexdigest())
回答by zerkms
Postgresql hashed passwords have md5
prefix:
Postgresql 散列密码有md5
前缀:
md548503dfd58720bd5ff35c102065a52d7
回答by RalphShnelvar
The answer provided by @zerkms is partially correct. It led me to the right answer.
@zerkms 提供的答案部分正确。它让我得到了正确的答案。
The answer provided in Generating postgresql user passwordis the answer that works for me.
在所提供的答案生成PostgreSQL用户密码是对我工作的答案。