| 1 |
-- |
| 2 |
-- crypt() and gen_salt(): crypt-des |
| 3 |
-- |
| 4 |
SELECT crypt('', 'NB'); |
| 5 |
crypt |
| 6 |
--------------- |
| 7 |
NBPx/38Y48kHg |
| 8 |
(1 row) |
| 9 |
|
| 10 |
SELECT crypt('foox', 'NB'); |
| 11 |
crypt |
| 12 |
--------------- |
| 13 |
NB53EGGqrrb5E |
| 14 |
(1 row) |
| 15 |
|
| 16 |
-- We are supposed to pass in a 2-character salt. |
| 17 |
-- error since salt is too short: |
| 18 |
SELECT crypt('password', 'a'); |
| 19 |
ERROR: invalid salt |
| 20 |
CREATE TABLE ctest (data text, res text, salt text); |
| 21 |
INSERT INTO ctest VALUES ('password', '', ''); |
| 22 |
UPDATE ctest SET salt = gen_salt('des'); |
| 23 |
UPDATE ctest SET res = crypt(data, salt); |
| 24 |
SELECT res = crypt(data, res) AS "worked" |
| 25 |
FROM ctest; |
| 26 |
worked |
| 27 |
-------- |
| 28 |
t |
| 29 |
(1 row) |
| 30 |
|
| 31 |
-- check disabling of built in crypto functions |
| 32 |
SET pgcrypto.builtin_crypto_enabled = off; |
| 33 |
UPDATE ctest SET salt = gen_salt('des'); |
| 34 |
ERROR: use of built-in crypto functions is disabled |
| 35 |
UPDATE ctest SET res = crypt(data, salt); |
| 36 |
ERROR: use of built-in crypto functions is disabled |
| 37 |
RESET pgcrypto.builtin_crypto_enabled; |
| 38 |
DROP TABLE ctest; |