2023-06-10 18:02:20 +00:00
|
|
|
select create_newtype_text('public.hashed_text');
|
2023-06-10 16:24:16 +00:00
|
|
|
|
|
|
|
create function hash_text(plain text)
|
|
|
|
returns hashed_text
|
|
|
|
language plpgsql
|
|
|
|
immutable
|
|
|
|
as $$
|
|
|
|
begin
|
2023-06-10 18:02:20 +00:00
|
|
|
return hashed_text_of_string(crypt(plain, gen_salt('bf')));
|
2023-06-10 16:24:16 +00:00
|
|
|
end;
|
|
|
|
$$;
|
|
|
|
|
|
|
|
create function hashed_text_matches(plain text, hashed hashed_text)
|
|
|
|
returns boolean
|
|
|
|
language plpgsql
|
|
|
|
immutable
|
|
|
|
as $$
|
|
|
|
begin
|
2023-06-10 18:02:20 +00:00
|
|
|
return hashed_text_to_string(hashed) = crypt(plain, hashed_text_to_string(hashed));
|
2023-06-10 16:24:16 +00:00
|
|
|
end;
|
|
|
|
$$;
|