feat: hashed_text fns

This commit is contained in:
Orion Kindel 2023-06-10 11:24:16 -05:00
parent 94501b7331
commit 047a51b45d
Signed by untrusted user who does not match committer: orion
GPG Key ID: 6D4165AE4C928719
7 changed files with 28 additions and 1 deletions

View File

@ -0,0 +1 @@
create extension pgcrypto;

View File

@ -1 +0,0 @@
create type hashed_text as (hashed text);

View File

@ -0,0 +1,27 @@
create type hashed_text as (hashed text);
create function hashed_text_string(hashed hashed_text)
returns text
language sql
immutable
as 'select (hashed.hashed);';
create function hash_text(plain text)
returns hashed_text
language plpgsql
immutable
as $$
begin
return row(crypt(plain, gen_salt('bf')));
end;
$$;
create function hashed_text_matches(plain text, hashed hashed_text)
returns boolean
language plpgsql
immutable
as $$
begin
return hashed_text_string(hashed) = crypt(plain, hashed_text_string(hashed));
end;
$$;