Monday, July 15, 2013

How to change user password in oracle apps

If it is required to change the user password using a API rather than accessing the
fron end, Here is how one can change the password.

DECLARE
   tmp_res      VARCHAR2 (1)   DEFAULT 'N';
   ln_updated   PLS_INTEGER  DEFAULT 0;
   ln_failed    PLS_INTEGER     DEFAULT 0;
   v_failed     VARCHAR2 (400) DEFAULT '';
   v_end_date   DATE;
   b_ok            BOOLEAN;
BEGIN
   FOR apps_users IN (SELECT *
                        FROM fnd_user
                       WHERE user_name = 'STEPHAN')
   LOOP
      SELECT end_date
        INTO v_end_date
        FROM fnd_user
       WHERE user_name = apps_users.user_name;

      IF v_end_date IS NOT NULL
      THEN
         UPDATE apps.fnd_user
            SET end_date = NULL
          WHERE user_name = apps_users.user_name;
      END IF;

      tmp_res :=
         apps.fnd_web_sec.change_password (apps_users.user_name,
                                           'We1c0me@user',
                                           FALSE
                                          );

      IF tmp_res = 'Y'
      THEN
         DBMS_OUTPUT.put_line ('Password updated');
         ln_updated := ln_updated + 1;
      ELSE
         v_failed := v_failed || '''' || apps_users.user_name || '''' || ', ';
         ln_failed := ln_failed + 1;
         DBMS_OUTPUT.put_line ('Password not updated');
      END IF;
   END LOOP;

   COMMIT;
EXCEPTION
   WHEN OTHERS
   THEN
         DBMS_OUTPUT.put_line ('Error while updating Password: '||sqlerrm);
END;

No comments:

Post a Comment