]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/xxxx.function.actor_change_password.sql
88aa119bad92bee9758d6deb7a95ae918d0187d1
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / xxxx.function.actor_change_password.sql
1 BEGIN;
2
3 SELECT evergreen.upgrade_deps_block_check('xxxx', :eg_version);
4
5 CREATE OR REPLACE FUNCTION actor.change_password (user_id INT, new_pw TEXT, pw_type TEXT DEFAULT 'main')
6 RETURNS VOID AS $$
7 DECLARE
8     new_salt TEXT;
9 BEGIN
10     SELECT actor.create_salt(pw_type) INTO new_salt;
11
12     IF pw_type = 'main' THEN
13         -- Only 'main' passwords are required to have
14         -- the extra layer of MD5 hashing.
15         PERFORM actor.set_passwd(
16             user_id, pw_type, md5(new_salt || md5(new_pw)), new_salt
17         );
18
19     ELSE
20         PERFORM actor.set_passwd(user_id, pw_type, new_pw, new_salt);
21     END IF;
22 END;
23 $$ LANGUAGE 'plpgsql';
24
25 COMMIT;