Postgres chkpass 比较 'contain' 而不是 'equal'

Postgres chkpass compares 'contain' and not 'equal'

我注意到 postgres 使用 'contain' 而不是 'equal' 来比较加密文本。 要复制使用这个:

create table "user" (uname text, password chkpass);
insert into "user" values ('user1', 'password')
select * from "user" where uname = 'user1' and password = 'password1'

这是个大问题。

有人注意到了吗?有人可以给我临时解决方案吗?

这不是错误。这只是加密内部使用的 crypt() 函数的限制。

I noticed that postgres compares encrypted text using 'contain' and not 'equal'.

它没有使用 'contain',而是检查正在比较的文本的前八个字符。如 Documentation of chkpass

中所述

The encryption uses the standard Unix function crypt(), and so it suffers from all the usual limitations of that function; notably that only the first eight characters of a password are considered.

我建议您使用其他算法来加密您的密码(如前所述 in this post),然后将其存储在数据库中,而不是使用 postgres chkpass。