加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在PostgreSQL中创建具有加密密码的用户

发布时间:2020-12-13 16:44:29 所属栏目:百科 来源:网络整理
导读:是否可以在PostgreSQL中创建一个用户,而不提供纯文本密码(理想情况下,我想创建一个用户只提供密码用sha-256加密)? 我想做的是创建一个类似这样的用户: CREATE USER "martin" WITH PASSWORD '$6$kH3l2bj8iT$KKrTAKDF4OoE7w.oy(...)BPwcTBN/V42hqE.'; 有什
是否可以在PostgreSQL中创建一个用户,而不提供纯文本密码(理想情况下,我想创建一个用户只提供密码用sha-256加密)?

我想做的是创建一个类似这样的用户:

CREATE USER "martin" WITH PASSWORD '$6$kH3l2bj8iT$KKrTAKDF4OoE7w.oy(...)BPwcTBN/V42hqE.';

有什么办法吗?

感谢您的帮助。

您可以提供已使用md5哈希的密码,如文档( CREATE ROLE)中所述:

ENCRYPTED UNENCRYPTED These key words control whether the password is
stored encrypted in the system catalogs. (If neither is specified,the
default behavior is determined by the configuration parameter
password_encryption.) If the presented password string is already in
MD5-encrypted format,then it is stored encrypted as-is
,regardless of
whether ENCRYPTED or UNENCRYPTED is specified (since the system cannot
decrypt the specified encrypted password string). This allows
reloading of encrypted passwords during dump/restore.

这里缺少的信息是MD5加密的字符串应该是用户名连接的密码,加上开头的md5。

例如,使用密码foobar创建u0,知道md5(‘foobaru0’)是ac4bbe016b808c3c0b816981f240dcae:

CREATE USER u0 PASSWORD 'md5ac4bbe016b808c3c0b816981f240dcae';

然后u0将能够通过键入foobar作为密码登录。

我不认为目前有一种方法使用SHA-256而不是md5的PostgreSQL密码。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读