35 lines
715 B
MySQL
35 lines
715 B
MySQL
|
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$
|
||
|
;
|
||
|
|
||
|
|