29th September 2022: PostgreSQL 15 RC 1 Released!
Supported Versions: 10
Unsupported versions: 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3

F.8. chkpass

This module implements a data type chkpass that is designed for storing encrypted passwords. Each password is automatically converted to encrypted form upon entry, and is always stored encrypted. To compare, simply compare against a clear text password and the comparison function will encrypt it before comparing.

There are provisions in the code to report an error if the password is determined to be easily crackable. However, this is currently just a stub that does nothing.

If you precede an input string with a colon, it is assumed to be an already-encrypted password, and is stored without further encryption. This allows entry of previously-encrypted passwords.

On output, a colon is prepended. This makes it possible to dump and reload passwords without re-encrypting them. If you want the encrypted password without the colon then use the raw() function. This allows you to use the type with things like Apache's Auth_PostgreSQL module.

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.

Note that the chkpass data type is not indexable.

Sample usage:

test=# create table test (p chkpass);
test=# insert into test values ('hello');
test=# select * from test;
(1 row)

test=# select raw(p) from test;
(1 row)

test=# select p = 'hello' from test;
(1 row)

test=# select p = 'goodbye' from test;
(1 row)

F.8.1. Author

D'Arcy J.M. Cain ()

Submit correction

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.