From bea07c5ab7308da0b755f2ebec87be3bb372c286 Mon Sep 17 00:00:00 2001 From: dodger Date: Fri, 21 Jan 2022 17:38:48 +0100 Subject: [PATCH] changed pwdhistory table added additional fields for more infomation --- passchanger.sql | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/passchanger.sql b/passchanger.sql index b9f4fd1..3a066e3 100644 --- a/passchanger.sql +++ b/passchanger.sql @@ -15,6 +15,8 @@ grant pg_read_all_stats to dba ; CREATE TABLE IF NOT EXISTS dba.pwdhistory ( usename character varying COLLATE pg_catalog."default", + usename_addres character varying COLLATE pg_catalog."default", + application_name character varying COLLATE pg_catalog."default", password character varying COLLATE pg_catalog."default", changed_on timestamp without time zone ) @@ -76,8 +78,12 @@ AS $BODY$ declare _min_password_length int := 8; -- specify min length here _usename text := ''; + _useraddress text := ''; + _userapp text := ''; begin select user into _usename; + select client_addr user into _useraddress from pg_stat_activity where pid = pg_backend_pid() ; + select application_name user into _userapp from pg_stat_activity where pid = pg_backend_pid() ; if length(_password) >= _min_password_length then EXECUTE format('ALTER USER %I WITH PASSWORD %L', _usename, _password); else -- also catches NULL @@ -93,8 +99,8 @@ begin , detail = 'Use a named user only.' ; else insert into dba.pwdhistory - (usename, password, changed_on) - values (_usename, md5(_password),now()); + (usename, usename_addres, application_name, password, changed_on) + values (_usename, _useraddress, _userapp, md5(_password),now()); PERFORM dba.change_valid_until(_usename) ; end if;