Notes2/sql/00022.sql
Magnus Åhall 9a164b984a wip
2024-11-29 09:15:42 +01:00

22 lines
348 B
PL/PgSQL

CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE FUNCTION public.password_hash(salt_hex char(32), pass bytea)
RETURNS char(96)
LANGUAGE plpgsql
AS
$$
BEGIN
RETURN (
SELECT
salt_hex ||
encode(
sha256(
decode(salt_hex, 'hex') || /* salt in binary */
pass /* password */
),
'hex'
)
);
END;
$$;