Monday, May 4, 2015

API to change the password of an Application User

Use the below code to change the password for all the application users. I have used this to change passwords of all application users who has been created after 01-Jan-2015.

To change password for single user remove the for loop and un-comment the local variables. Amend as per your requirement.

DECLARE
--v_user_name varchar2(30):=upper('&Enter_User_Name');
--v_new_password varchar2(30):='&Enter_New_Password';
   v_status   BOOLEAN;

   CURSOR c1
   IS
      SELECT user_name
        FROM fnd_user
       WHERE TRUNC (creation_date) > '01-Jan-2015';

BEGIN
   FOR i IN c1
   LOOP
      v_status :=
         fnd_user_pkg.changepassword (username         => i.user_name, --v_user_name
                                      newpassword      => 'newpassword' --v_new_password
                                     );

      IF v_status = TRUE
      THEN
         DBMS_OUTPUT.put_line
                          (   'The password reset successfully for the User:'
                           || i.user_name
                          );
         COMMIT;
      ELSE
         DBMS_OUTPUT.put_line (   'Unable to reset password due to'
                               || SQLCODE
                               || ' '
                               || SUBSTR (SQLERRM, 1, 100)
                              );
         ROLLBACK;

      END IF;

   END LOOP;

END;