Use uuid-ossp extension rather than custom function
This commit is contained in:
@@ -4,20 +4,12 @@
|
|||||||
begin;
|
begin;
|
||||||
|
|
||||||
create extension if not exists pgcrypto;
|
create extension if not exists pgcrypto;
|
||||||
|
create extension if not exists "uuid-ossp";
|
||||||
create schema if not exists basic_auth;
|
create schema if not exists basic_auth;
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- Utility functions
|
-- Utility functions
|
||||||
|
|
||||||
create or replace function
|
|
||||||
basic_auth.random_value(len int, out result varchar(32)) as
|
|
||||||
$$
|
|
||||||
BEGIN
|
|
||||||
SELECT substring(md5(random()::text),0, len) into result;
|
|
||||||
END
|
|
||||||
$$ LANGUAGE plpgsql;
|
|
||||||
|
|
||||||
|
|
||||||
create or replace function
|
create or replace function
|
||||||
basic_auth.clearance_for_role(u name) returns void as
|
basic_auth.clearance_for_role(u name) returns void as
|
||||||
$$
|
$$
|
||||||
@@ -96,7 +88,7 @@ basic_auth.send_validation() returns trigger
|
|||||||
declare
|
declare
|
||||||
tok character varying;
|
tok character varying;
|
||||||
begin
|
begin
|
||||||
select basic_auth.random_value(64) into tok;
|
select uuid_generate_v4() into tok;
|
||||||
insert into basic_auth.tokens (token, token_type, username)
|
insert into basic_auth.tokens (token, token_type, username)
|
||||||
values (tok, 'validation', new.username);
|
values (tok, 'validation', new.username);
|
||||||
perform pg_notify('validate',
|
perform pg_notify('validate',
|
||||||
@@ -161,7 +153,7 @@ begin
|
|||||||
where token_type = 'reset'
|
where token_type = 'reset'
|
||||||
and tokens.username = request_password_reset.username;
|
and tokens.username = request_password_reset.username;
|
||||||
|
|
||||||
select basic_auth.random_value(64) into tok;
|
select uuid_generate_v4() into tok;
|
||||||
insert into basic_auth.tokens (token, token_type, username)
|
insert into basic_auth.tokens (token, token_type, username)
|
||||||
values (tok, 'reset', request_password_reset.username);
|
values (tok, 'reset', request_password_reset.username);
|
||||||
perform pg_notify('reset',
|
perform pg_notify('reset',
|
||||||
@@ -204,7 +196,7 @@ begin
|
|||||||
where token_type = 'reset'
|
where token_type = 'reset'
|
||||||
and tokens.username = reset_password.username;
|
and tokens.username = reset_password.username;
|
||||||
|
|
||||||
select basic_auth.random_value(64) into tok;
|
select uuid_generate_v4() into tok;
|
||||||
insert into basic_auth.tokens (token, token_type, username)
|
insert into basic_auth.tokens (token, token_type, username)
|
||||||
values (tok, 'reset', reset_password.username);
|
values (tok, 'reset', reset_password.username);
|
||||||
perform pg_notify('reset',
|
perform pg_notify('reset',
|
||||||
|
|||||||
Reference in New Issue
Block a user