db/94501b7_to_047a51b.sql
2023-07-18 21:32:10 -05:00

33 lines
713 B
PL/PgSQL

create extension if not exists "pgcrypto" with schema "public" version '1.3';
set check_function_bodies = off;
CREATE OR REPLACE FUNCTION public.hash_text(plain text)
RETURNS hashed_text
LANGUAGE plpgsql
IMMUTABLE
AS $function$
begin
return row(crypt(plain, gen_salt('bf')));
end;
$function$
;
CREATE OR REPLACE FUNCTION public.hashed_text_matches(plain text, hashed hashed_text)
RETURNS boolean
LANGUAGE plpgsql
IMMUTABLE
AS $function$
begin
return hashed_text_string(hashed) = crypt(plain, hashed_text_string(hashed));
end;
$function$
;
CREATE OR REPLACE FUNCTION public.hashed_text_string(hashed hashed_text)
RETURNS text
LANGUAGE sql
IMMUTABLE
AS $function$select (hashed.hashed);$function$
;