From 2ce1a38783b70ba5c2a4e7a566dfb4defc0a44ba Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 19 Jun 2019 17:41:01 -0400 Subject: [PATCH] JBAS-1832 Add change_password DB function Signed-off-by: Bill Erickson --- KCLS/sql/schema/deploy/3.2-post-base-schema.sql | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/KCLS/sql/schema/deploy/3.2-post-base-schema.sql b/KCLS/sql/schema/deploy/3.2-post-base-schema.sql index f3536d77ae..0217abd8d3 100644 --- a/KCLS/sql/schema/deploy/3.2-post-base-schema.sql +++ b/KCLS/sql/schema/deploy/3.2-post-base-schema.sql @@ -426,6 +426,28 @@ BEGIN END IF; END $INSERT$; +-- utility sql for modifying user 'main' passwords +CREATE OR REPLACE FUNCTION evergreen.change_password + (user_id INT, new_pw TEXT, pw_type TEXT DEFAULT 'main') +RETURNS VOID AS $$ +DECLARE + new_salt TEXT; +BEGIN + SELECT actor.create_salt(pw_type) INTO new_salt; + + IF pw_type = 'main' THEN + -- Only 'main' passwords are required to have + -- the extra layer of MD5 hashing. + PERFORM actor.set_passwd( + user_id, pw_type, md5(new_salt || md5(new_pw)), new_salt + ); + + ELSE + PERFORM actor.set_passwd(user_id, pw_type, new_pw, new_salt); + END IF; +END; +$$ LANGUAGE 'plpgsql'; COMMIT; + -- 2.11.0