从自定义表对用户进行身份验证,检查密码是否已过期,进行通知并重定向

时间:2019-10-28 14:35:22

标签: oracle oracle-apex

希望你一切都好。请帮忙。我有一个使用自定义身份验证功能的应用程序,用于检查用户是否存在,输入的密码与表上的密码匹配,帐户处于活动状态并且密码已过期。如何设置和通知(密码何时过期)以及如何重定向到更改密码页面

create or replace FUNCTION AUTHENTICATE_USER
    (p_username in varchar2,
     p_password in varchar2)
return boolean
is
    l_user_name users.user_name%type := upper(p_username);
    l_password users.password%type;
    l_hashed_password varchar2(1000);
    l_password_expiry date;
    l_count number;
begin
    select count(*)
    into l_count
    from users
    where 
        user_name = l_user_name and password_expiry > trunc(sysdate) and status = 'Active';

    if 
        l_count > 0 
    then
        l_hashed_password := hash_password(l_user_name, p_password);

        select 
            password
        into 
            l_password
        from 
            users
        where 
            user_name = l_user_name;    

        if 
            l_hashed_password = l_password then
            APEX_UTIL.SET_AUTHENTICATION_RESULT(0);
            return true;
        else
            APEX_UTIL.SET_AUTHENTICATION_RESULT(4);
            return false;
        end if;

    else
        APEX_UTIL.SET_AUTHENTICATION_RESULT(1);
        return false;
    end if;

    APEX_UTIL.SET_AUTHENTICATION_RESULT(7);
    return false;
    exception
when others then
    APEX_UTIL.SET_AUTHENTICATION_RESULT(7);
    APEX_UTIL.SET_CUSTOM_AUTH_STATUS(sqlerrm);
    return false;
end AUTHENTICATE_USER;

0 个答案:

没有答案