如何在 oracle 中更新 VERIFY_PASSWORD_FUNCTION 让用户在 change/alter 之前至少保留他的密码 1 天
How to update a VERIFY_PASSWORD_FUNCTION in oracle for users to retain his password for 1 day at least before change/alter it
这是客户需要Oracle用户不会很快更改密码的要求之一,因此他们需要至少保留一天才能更改密码。所以它不能在同一天更改,我们必须更新 VERIFY_PASSWORD_FUNCTION 代码以设置最低密码期限 1 天。
在 "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 用户的密码。
这是客户需要Oracle用户不会很快更改密码的要求之一,因此他们需要至少保留一天才能更改密码。所以它不能在同一天更改,我们必须更新 VERIFY_PASSWORD_FUNCTION 代码以设置最低密码期限 1 天。
在 "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 用户的密码。