feat: hashed_text fns
This commit is contained in:
parent
94501b7331
commit
047a51b45d
1
schema/000_extensions.sql
Normal file
1
schema/000_extensions.sql
Normal file
@ -0,0 +1 @@
|
||||
create extension pgcrypto;
|
@ -1 +0,0 @@
|
||||
create type hashed_text as (hashed text);
|
27
schema/010_hashed_text.sql
Normal file
27
schema/010_hashed_text.sql
Normal 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;
|
||||
$$;
|
Loading…
Reference in New Issue
Block a user