This discussion is archived
12 Replies Latest reply: Dec 18, 2012 2:54 AM by yoman RSS

Change Password page (Apex Authentication)

yoman Newbie
Currently Being Moderated
Hi,
I am using
Apex 4.1
Oracle DB 10g XE

I am using Apex Authentication for the applications developed in Apex. The apps are working fine but I require a Change Password page for the application. I created a normal HTML page with 3 fields as
P8_OLD_PASSWORD
P8_NEW_PASSWORD
P8_RETYPE_PASSWORD
and an item button as P8_CHANGE

The action for button is "Submit Page" with Execute validation as "YES"

There is a process on page that runs "On Submit after computation and validation" with process source as
APEX_UTIL.CHANGE_CURRENT_USER_PW (:P8_NEW_PASSWORD);

Till here system works fine if user enters a value in field ":P8_NEW_PASSWORD". I also want the page to validate user entry in other fields which is as below:
A validation of type Function returning Error Text with Expression1 as
DECLARE
l_username varchar2(30);
l_password varchar2(30);
l_old_password varchar2(30);

BEGIN
l_username := :APP_USER;
l_password := :P8_NEW_PASSWORD;
l_old_password := :P8_OLD_PASSWORD;
if :P8_NEW_PASSWORD != :P8_RETYPE_PASSWORD then
return 'New and Confirm Passwords do not match!';

elsif :P8_NEW_PASSWORD is null or :P8_RETYPE_PASSWORD is null then
return 'New and Confirm Passwords should not be empty!';
elsif APEX_UTIL.IS_LOGIN_PASSWORD_VALID (l_username,l_old_password) = false then
return 'Old Password is invalid!';
else
return null;
end if;
END;
After this validation creation, the system neither shows any error, nor it changes the password. Please help.

Thanks
Saurabh
  • 1. Re: Change Password page (Apex Authentication)
    714270 Pro
    Currently Being Moderated
    Hi Saurabh,


    I do not see any problem with your code. Could you reproduce this in apex.oracle.com?


    Thanks,
    Rohit
  • 2. Re: Change Password page (Apex Authentication)
    yoman Newbie
    Currently Being Moderated
    The application can be accessed with these details

    Workspace: apexbuilder
    user: SJ
    pwd: 12345678

    Application name: tests
    Page : 8
  • 3. Re: Change Password page (Apex Authentication)
    714270 Pro
    Currently Being Moderated
    It seems to work. I am able to change your password to 123456.
  • 4. Re: Change Password page (Apex Authentication)
    yoman Newbie
    Currently Being Moderated
    Thanks for your efforts. I just tried it with the "SJ" and password change is working ( maybe because SJ has developer role).

    I was testing it using
    user: guest (which is an end user) for 2-3 days and it wasnt working at all. Now it is working with guest user also.
    Maybe you or somebody else made any change to it. If that is the case, then kindly update me, so that I can implement it in my actual application.

    Anyways thanks for your help.
    Saurabh
  • 5. Re: Change Password page (Apex Authentication)
    714270 Pro
    Currently Being Moderated
    I did not change anything.
  • 6. Re: Change Password page (Apex Authentication)
    yoman Newbie
    Currently Being Moderated
    I just found what the problem was. I was pressing "Enter" from keyboard when on field P8_RETYPE_PASSWORD which had the setting for "Submit when Enter pressed" as YES and therefore it would submit the page without triggering the page process and validation as they were tied to the button "P8_CHANGE"

    So the system works if user clicks the button but not if Enter is pressed. I have now disabled the setting for Enter, so there is only one way left using button clicking.
    Thanks
  • 7. Re: Change Password page (Apex Authentication)
    714270 Pro
    Currently Being Moderated
    Hi Saurabh,

    You can make it work with the "Enter" key also. Write a simple javascript function on the page header to identify the "enter" key press as:
    <script language="javascript">
    NS4 = (document.layers) ? true : false;
    function checkEnter(event)
    {
    var code = 0;
    if (NS4)
    code = event.which;
    else
    code = event.keyCode;
    if (code==13)
    apex.submit('<your-button-name-here>');
    }
    </script>
    The above will submit the page with the REQUEST defined in apex.submit.

    In the "Retype Password" field, call this function as (in the HTML Form Element Attributes):
    onKeyPress="checkEnter(event)"
    Thanks,
    Rohit
  • 8. Re: Change Password page (Apex Authentication)
    yoman Newbie
    Currently Being Moderated
    Hi, Thanks a lot for all the help.

    I tried it while replacing with the button name in the code and adding the call to the retype_password field. It still isnt working using Enter press.
    If you can take a look at it, then please help. The login details are still the same as put above.

    Thanks
    Saurabh
  • 9. Re: Change Password page (Apex Authentication)
    714270 Pro
    Currently Being Moderated
    Fixed this issue; you do not need the colon (:) with the button name when submitting the page.
    I modified the following line in the javascript function from
    apex.submit(':P8_CHANGE');
    to
    apex.submit('P8_CHANGE');
    I have changed your password to 12345.

    BTW, if your issue is resolved, please do not forget to mark the answer as correct. It will help all of us.
  • 10. Re: Change Password page (Apex Authentication)
    fac586 Guru
    Currently Being Moderated
    Saurabh wrote:
    I just found what the problem was. I was pressing "Enter" from keyboard when on field P8_RETYPE_PASSWORD which had the setting for "Submit when Enter pressed" as YES and therefore it would submit the page without triggering the page process and validation as they were tied to the button "P8_CHANGE"
    Rohit Kapoor wrote:You can make it work with the "Enter" key also. Write a simple javascript function on the page header to identify the "enter" key press as:
    <script language="javascript">
    NS4 = (document.layers) ? true : false;
    function checkEnter(event)
    {
    var code = 0;
    if (NS4)
    code = event.which;
    else
    code = event.keyCode;
    if (code==13)
    apex.submit('<your-button-name-here>');
    }
    </script>
    The above will submit the page with the REQUEST defined in apex.submit.

    In the "Retype Password" field, call this function as (in the HTML Form Element Attributes):
    onKeyPress="checkEnter(event)"
    That's a lot more complicated than it needs to be. If the page is submitted using a text item with "Submit when Enter pressed", then the <tt>REQUEST</tt> value is set to the name of the item. So to fire validations and processes when either the Change button is clicked or enter is pressed in the P8_RETYPE_PASSWORD item, change conditions on the validations and processes to condition type Request Is Contained within Expression 1, with Expression 1:
    P8_CHANGE,P8_RETYPE_PASSWORD
  • 11. Re: Change Password page (Apex Authentication)
    714270 Pro
    Currently Being Moderated
    That's a lot more complicated than it needs to be. If the page is submitted using a text item with "Submit when Enter pressed", then the <tt>REQUEST</tt> value is set to the name of the item. So to fire validations and processes when either the Change button is clicked or enter is pressed in the P8_RETYPE_PASSWORD item, change conditions on the validations and processes to condition type Request Is Contained within Expression 1, with Expression 1:
    P8_CHANGE,P8_RETYPE_PASSWORD
    Oh yes, that's a much easier way to do this. Not sure why I did not think about it earlier.

    Thanks for the reply.
  • 12. Re: Change Password page (Apex Authentication)
    yoman Newbie
    Currently Being Moderated
    Thanks to both fac586 and Rohit. Both the problems are resolved now.

    To summarize it all for everyone Else's reference, here it is

    1) First I created the blank page with an HTML region and created 3 fields (all of type password)
    P??_OLD_PASSWORD
    P??_NEW_PASSWORD
    P??_RETYPE_PASSWORD
    and also created page item button named P??_CHANGE

    2) I used the code provided here
    WORKING Password Change page (APEX users)
    to create a validation and process. I slightly modified the validation as put below
    DECLARE
    l_username varchar2(30);
    l_password varchar2(30);
    l_old_password varchar2(30);
    
    BEGIN
    l_username := :APP_USER;
    l_password := :P??_NEW_PASSWORD;          -- replace ?? with page number
    l_old_password := :P??_OLD_PASSWORD;
    if :P??_NEW_PASSWORD != :P??_RETYPE_PASSWORD then
    return 'New and Confirm Passwords do not match!';
    
    elsif :P??_NEW_PASSWORD is null or :P??_RETYPE_PASSWORD is null then
    return 'New and Confirm Passwords should not be empty!';
    elsif APEX_UTIL.IS_LOGIN_PASSWORD_VALID (l_username,l_old_password) = false then
    return 'Old Password is invalid!';
    else
    return null;
    end if;
    END;
    The Condition for the validation is
    "When Button Pressed" --> "- Select Button -"
    "Condition Type" --> "Request is Contained within Expression 1"
    "Expression 1" --> "P??_CHANGE,P??_RETYPE_PASSWORD" -- replace ?? with page number

    The Page Process is similar to the one mentioned in link above with Condition values same as above
    Once done all this, I created a Navigation bar entry to point to the password change page and its all good.

    P.S. :- The code given by Rohit is also correct and does the job, but yes fac586's method is lot simpler.
    Thanks again to both

    Edited by: Saurabh on Dec 18, 2012 4:23 PM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points