使用profile的PASSWORD_VERIFY_FUNCTION参数实现自定义的密码验证规则

 

      profile的PASSWORD_VERIFY_FUNCTION参数,允许我们在创建用户或者更改用户
密码时实施自定义的密码验证规则。

       1.首先,我们需要创建一个自己的实现密码验证规则的函数,该函数必须创建在sys模式
下,而且必须有三个类型为varchar2的输入参数,第一个参数,包含我们要修改的用户名,第
二个参数包含新密码,第三个参数包含旧密码,并且返回类型为布尔类型。

      举一个简单的例子,如果我们需要使密码最少保持6位,并在用户修改密码时在
      sys.passwd_changed表中记录用户的旧密码和新密码:
     
      首先创建表passwd_changed:
     
      SQL> conn sys/*** as sysdba
      Connected.
      SQL> create table passwd_changed
        2  (
        3    user_name  varchar2(20) ,
        4    old_passwd varchar2(100) ,
        5    new_passwd varchar2(100)
        6  )
        7  ;
     
      Table created.
     
      创建实现密码自定义规则的函数my_password_verify:
     
      SQL> CREATE OR REPLACE FUNCTION my_password_verify   (username VARCHAR2   ,password VARCHAR2   ,old_password VARCHAR2   ) RETURN BOOLEAN IS
        2  BEGIN
        3  IF LENGTH(password) < 6 THEN
        4  raise_application_error(-20001,'Password must be at least 6 characters long');
        5  END IF;
        6  INSERT INTO passwd_changed VALUES(username,old_password,password);
        7  RETURN(TRUE);
        8  END;
        9  /
     
      Function created.
     
      2.创建profile实施自定义密码验证规则:
     
      SQL> create profile TEST_PROFILE limit
      2    password_verify_function MY_PASSWORD_VERIFY;
   
       Profile created.
      
      3.使用我们创建的profile:TEST_PROFILE 创建用户test_user,密码为test,看看会发生
      什么:
      SQL> create user test_user
        2    identified by test
        3    default tablespace USERS
        4    temporary tablespace temp
        5    profile TEST_PROFILE;
      create user test_user
      *
      ERROR at line 1:
      ORA-28003: password verification for the specified password failed
      ORA-20001: Password must be at least 6 characters long
     
      可以看到,我们自定义的密码验证规则已经生效,密码:test长度小于6位时,创建用户失败。
     
      4.我们修改密码为test12,重新创建用户test_user:
     
      SQL> create user test_user
      2    identified by test12
      3    default tablespace USERS
      4    temporary tablespace temp
      5    profile TEST_PROFILE;
   
      User created.
     
     
      密码:test12长度等于6位时,创建用户成功。
     
      5.检查sys.passwd_changed表数据:
      SQL> select * from sys.passwd_changed;
 
      USER_NAME   OLD_PASSWD     NEW_PASSWD
      -------------------- -------------------------
      TEST_USER                              TEST12
 
      6.更改test_user的密码为test,看看是否可以成功:
     
      SQL> alter user test_user identified by test;
 
       alter user test_user identified by test
       
       ORA-28003: password verification for the specified password failed
       ORA-20001: Password must be at least 6 characters long
 
      7.更改test_user的密码为test123,看看是否可以成功:
     
      SQL> alter user test_user identified by test123;
 
       User altered
 
     
     8.检查sys.passwd_changed表数据:
    
     SQL> select * from sys.passwd_changed;
 
     USER_NAME   OLD_PASSWD     NEW_PASSWD
     -------------------- -------------------------
     TEST_USER                              TEST12
     TEST_USER                              TEST123
     
     
     
      
        

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
In Oracle, the PASSWORD_VERIFY_FUNCTION is a built-in function that allows you to enforce password complexity rules and policies when creating or altering user passwords. It helps to ensure that passwords meet certain requirements and enhances the security of the Oracle database. By default, Oracle provides a default password verification function called "ORA12C_STRONG_VERIFY_FUNCTION". This function enforces the following password complexity rules: 1. The password must be at least 8 characters long. 2. It must contain at least one uppercase letter. 3. It must contain at least one lowercase letter. 4. It must contain at least one numeric digit. 5. It must contain at least one special character (e.g., !@#$%^&*). You can view the details of this default password verification function by querying the DBA_USERS view: ```sql SELECT * FROM DBA_USERS; ``` To alter the password complexity rules or create a custom password verification function, you can use the DBMS_AUTHENTICATION package. Here's an example of how to create a custom password verification function in Oracle: ```sql CREATE OR REPLACE FUNCTION my_password_verify_function ( username IN VARCHAR2, password IN VARCHAR2, old_password IN VARCHAR2 ) RETURN BOOLEAN IS -- Custom password verification logic goes here BEGIN -- Return TRUE if the password meets the desired criteria, otherwise FALSE END; / ``` Once you have created your custom password verification function, you can set it as the current password verification function using the ALTER PROFILE statement: ```sql ALTER PROFILE my_profile LIMIT PASSWORD_VERIFY_FUNCTION my_password_verify_function; ``` This will enforce your custom password complexity rules for new passwords or when altering existing passwords for users associated with the specified profile. Remember to adjust the logic inside your custom password_verify_function to fit your specific requirements for password complexity and security.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值