Skip to content
Snippets Groups Projects
Commit 6d726c20 authored by Anton Bagliy's avatar Anton Bagliy
Browse files

WIP: createauthtoken #331

parent 0a86906f
Branches
No related merge requests found
CREATE OR REPLACE FUNCTION public.createauthtoken(paccountid integer, pdescription character varying, prightmask integer)
RETURNS character varying
LANGUAGE plpgsql
AS $function$
DECLARE vTries int DEFAULT 13; -- number of tries to generate unique token
vCreated boolean DEFAULT FALSE;
-- vSeed int DEFAULT FLOOR(4294967296 * RAND(CURRENT_TIMESTAMP ^ LAST_INSERT_ID() ^ (pAccountID << 10)));
vToken char(40);
BEGIN
--select public.createauthtoken(
-- :paccountid, -- put the paccountid parameter value instead of 'paccountid' (int4)
-- :pdescription, -- put the pdescription parameter value instead of 'pdescription' (varchar)
-- :prightmask -- put the prightmask parameter value instead of 'prightmask' (int4)
--);
SELECT setseed(FLOOR(4294967296 * (CURRENT_TIMESTAMP # (pAccountID << 10)))); -- ???????
WHILE (NOT vCreated AND vTries > 0) loop
begin
vToken := SHA1(RANDOM());
vTries := vTries - 1;
vCreated := TRUE;
INSERT INTO auth_tokens(Token, AccountID, Description, Mask) VALUES (vToken, pAccountID, pDescription, pRightMask);
EXCEPTION
when others
then vCreated := FALSE;
end;
END loop;
RETURN IF(vCreated, vToken, NULL);
END
$function$;
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment