尝试一定数量的无效登录后如何锁定帐户

时间:2019-03-31 01:20:35

标签: oracle oracle-apex

我的oracle apex应用程序中有一个身份验证方案。我还将最终用户的用户名和密码存储在数据库中。因此,当用户登录时,他们将使用自己创建的用户名和密码(我不会为该用户创建任何帐户)。我要进行设置,以便如果帐户进行了太多无效的登录尝试(我应该能够解锁),帐户就会被锁定。

我所研究的唯一发现是我与管理表达有关,但我仍然不知道该如何提供帮助,也无法在oracle应用程序中找到此页面。我也不想让任何事情变得复杂,也许是顶点而不是代码(因为我不太了解函数/布尔值等)。

1 个答案:

答案 0 :(得分:2)

对于Application Express帐户身份验证, 它适用于使用Application Express最终用户帐户管理界面创建的最终用户帐户。

登录到Internal工作区并转到Manage Instance > Security > Authentication Control,转到Development Environment Settings并将Require User Account Expiration and Locking设置为“是”。 enter image description here

对于自定义身份验证,希望您可以将无效的用户尝试记录在日志表中,并基于连续的无效登录尝试的次数来限制/锁定用户。

下面的示例代码基于提供的link

创建一个USER_LOG表来记录无效尝试,如下所示

create table USER_LOG (username varchar2(4000), 
                       login_failed_count number, updated_on date);

更改现有的table1并为用户锁定添加一个标志(是-是用户锁定,否-否用户未锁定),如下所示。

Alter table table1 add is_locked varchar2(1) default 'N';

完成上述更改后,您可以尝试使用链接中提供的以下更新过程。

create or replace function Table1Authenticate( p_username varchar2, p_password varchar2 ) return boolean is  
   i integer;  
   l_rcnt number;
   l_failed_cnt number;
   l_max_failed_cnt number :=4;
   l_lock_flag varchar2(1);
begin     
    select  count(1)  into l_rcnt 
     from table1 t1  
     where t1.username = p_username  
     and   t1.password = p_password;

       if (l_rcnt > 0) then
          select is_locked into l_lock_flag from table1 where username = p_username
          and password = p_password;

          if (l_lock_flag ='N') then
             delete from USER_LOG where username=p_username;
             return true;
          elsif (l_lock_flag ='Y') then 
            apex_util.set_custom_auth_status (p_status => 'Account Locked, Exceeded Maximum Attempts..!');
            return false;
          end if;
       else
           merge into USER_LOG u
           using dual l
           on (u.username=p_username)
             when matched then
                update set login_failed_count=login_failed_count+1,updated_on=sysdate 
             when not matched then
                insert (username,login_failed_count,updated_on) values
                (p_username,1,sysdate);

           select login_failed_count into l_failed_cnt 
           from user_log where username =p_username;
              if (l_failed_cnt > l_max_failed_cnt) then
                 update table1 set is_locked='Y' where username=p_username;
              end if;
            return( false );  
       end if;
   exception when others then  
           return( false );  
end;  

要解锁用户,请将is_locked中的table1Y更新为N。使用前,请在多种情况下进行验证。希望这对您有所帮助。