changed pwdhistory table
added additional fields for more infomation
This commit is contained in:
parent
c1db5741db
commit
bea07c5ab7
@ -15,6 +15,8 @@ grant pg_read_all_stats to dba ;
|
|||||||
CREATE TABLE IF NOT EXISTS dba.pwdhistory
|
CREATE TABLE IF NOT EXISTS dba.pwdhistory
|
||||||
(
|
(
|
||||||
usename character varying COLLATE pg_catalog."default",
|
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",
|
password character varying COLLATE pg_catalog."default",
|
||||||
changed_on timestamp without time zone
|
changed_on timestamp without time zone
|
||||||
)
|
)
|
||||||
@ -76,8 +78,12 @@ AS $BODY$
|
|||||||
declare
|
declare
|
||||||
_min_password_length int := 8; -- specify min length here
|
_min_password_length int := 8; -- specify min length here
|
||||||
_usename text := '';
|
_usename text := '';
|
||||||
|
_useraddress text := '';
|
||||||
|
_userapp text := '';
|
||||||
begin
|
begin
|
||||||
select user into _usename;
|
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
|
if length(_password) >= _min_password_length then
|
||||||
EXECUTE format('ALTER USER %I WITH PASSWORD %L', _usename, _password);
|
EXECUTE format('ALTER USER %I WITH PASSWORD %L', _usename, _password);
|
||||||
else -- also catches NULL
|
else -- also catches NULL
|
||||||
@ -93,8 +99,8 @@ begin
|
|||||||
, detail = 'Use a named user only.' ;
|
, detail = 'Use a named user only.' ;
|
||||||
else
|
else
|
||||||
insert into dba.pwdhistory
|
insert into dba.pwdhistory
|
||||||
(usename, password, changed_on)
|
(usename, usename_addres, application_name, password, changed_on)
|
||||||
values (_usename, md5(_password),now());
|
values (_usename, _useraddress, _userapp, md5(_password),now());
|
||||||
PERFORM dba.change_valid_until(_usename) ;
|
PERFORM dba.change_valid_until(_usename) ;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user