首页 > 解决方案 > 如何在 oracle 中更新 VERIFY_PASSWORD_FUNCTION 以使用户在更改/更改密码之前至少将其密码保留 1 天

问题描述

这是客户需要那里的一项要求,Oracle 用户不会很快更改他的密码,因此他们需要至少保留一天才能更改密码。所以它不能在同一天更改,我们必须更新 VERIFY_PASSWORD_FUNCTION 代码以设置限制最低密码年龄 1 天。

标签: oraclepasswordsschemaverify

解决方案


在“VERIFY_PASSWORD_FUNCTION”函数中附加以下代码:

CREATE OR REPLACE FUNCTION "SYS"."VERIFY_PASSWORD_FUNCTION" 
(username varchar2,
password varchar2,
old_password varchar2)
RETURN boolean IS
last_change sys.user$.ptime%type;
minimum_age number :=1;
userexist integer;
begin
-- Set minimum password age 
select count(*) into userexist from sys.user$ where name=username;
if (userexist != 0) then
    select ptime into last_change from sys.user$ where name=username;
    if sysdate - last_change < minimum_age then
        raise_application_error(-20010, 'Password changed too soon');
    END IF; 
end if;
end;
/

从上面的代码中,您只需附加变量和逻辑。

这是一个测试用例:

SQL> create user TEST11 identified by asdfhe#24HyrE profile USERS;

User Created.

SQL> alter user test11 identified by asdfhe#24HyrWW;
alter user test11 identified by asdfhe#24HyrWW
*
ERROR at line 1:
ORA-28003: password verification for the specified password failed
ORA-20010: Password changed too soon

SQL> 

SQL> select name,ptime from user$ where name='TEST11';

NAME                           PTIME
------------------------------ ---------
TEST11                         08-NOV-18

SQL> update user$ set ptime='03-Nov-18' where name='TEST11';

1 row updated.

SQL> select name,ptime from user$ where name='TEST11';

NAME                           PTIME
------------------------------ ---------
TEST11                         03-NOV-18

SQL> commit;

Commit complete.

SQL> alter user test11 identified by asdfhe#24HyrWW;

User altered.

SQL>

由于我们无法在同一天内更改密码,因此我们更新了 ptime 值以验证并再次尝试更改 Test11 用户的密码。


推荐阅读