首页 > 解决方案 > 如何在一定次数的无效登录尝试后锁定帐户

问题描述

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

形成我研究的唯一我能找到的东西与管理快递有关,但我仍然不知道这有什么帮助,我也无法在我的 oracle 应用程序中找到这个页面。我也不想要任何复杂的东西,也许是在顶点而不是代码上的东西(因为我不太擅长理解函数/布尔值等)。

标签: oracleoracle-apex

解决方案


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

登录到Internal工作区并转到Manage Instance > Security > Authentication Control,转到Development Environment Settings 并设置Require User Account Expiration and Locking为是。在此处输入图像描述

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

下面的示例代码基于提供的链接

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

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

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

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_lockedin更新table1为。使用前请多场景验证。希望这对您有所帮助。YN


推荐阅读