From: Rogan Hamby Date: Wed, 8 Jan 2020 20:47:07 +0000 (-0500) Subject: convenience function for setting a salted password, copy and pasted from bug comment... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=28ba45bf4d980e3d8290e430a6d97d7beecd3d1d;p=working%2FEvergreen.git convenience function for setting a salted password, copy and pasted from bug comment by Bill Erickson --- diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 71aba5a30e..ca9d7494f0 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -887,6 +887,30 @@ Replaces an address with a pending address. This is done by giving the pending address the ID of the old address. The replaced address is retained with -id. $$; +CREATE OR REPLACE FUNCTION actor.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'; + +COMMENT ON FUNCTION actor.change_password(INT,TEXT,TEXT) IS $$ +Allows setting a salted password for a user by passing actor.usr id and the text of the password. +$$; + CREATE OR REPLACE FUNCTION container.clear_expired_circ_history_items( ac_usr IN INTEGER ) RETURNS VOID AS $$ diff --git a/Open-ILS/src/sql/Pg/upgrade/xxxx.function.actor_change_password.sql b/Open-ILS/src/sql/Pg/upgrade/xxxx.function.actor_change_password.sql new file mode 100644 index 0000000000..88aa119bad --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/xxxx.function.actor_change_password.sql @@ -0,0 +1,25 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('xxxx', :eg_version); + +CREATE OR REPLACE FUNCTION actor.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;