加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

使用profile的password_verify_function

(2009-08-19 11:32:19)
标签:

it

分类: ORACLE-BASIC

使用profile的password_verify_function实现用户自定义的密码验证规则。

先决条件:

1.此函数必须在sys用户下创建。

2.必须有三个varchar2类型的输入参数,第一个参数表示要修改的用户名,第二个参数表示输入的新密码,第三个参数表示旧密码

3.返回类型为bool类型。

纤细测试如下:

创建步骤如下:

1.创建测试表password_verify

2.创建验证函数user_password_verify

3.创建profile test_profile

4.创建测试用户test_user

rorke>show user
USER is "SYS"
sql>create table password_verify
  (user_name varchar2(30),
  old_password varchar2(30),
  new_password varchar2(100));

Table created.

sql>create or replace function user_password_verify (username varchar2,password varchar2,old_password varchar2) return boolean is
  begin
  if length(password) < 6 then
  raise_application_error(-20001,'Password must be at least 6 characters long')
  end if
  insert into password_verify values(username,old_password,password);
  return(true);
  end;
  /

Warning: Function created with compilation errors.

sql>show error
Errors for FUNCTION USER_PASSWORD_VERIFY:

LINE/COL ERROR                                                                 
-------- -----------------------------------------------------------------     
5/1      PLS-00103: Encountered the symbol "END" when expecting one of         
         the following:                                                        
         := . ( % ;                                                            
                                                                               
sql>list
  create or replace function user_password_verify (username varchar2,password varchar2,old_password varchar2) return boolean is
  begin
  if length(password) < 6 then
  raise_application_error(-20001,'Password must be at least 6 characters long')
  end if
  insert into password_verify values(username,old_password,password);
  return(true);
  8* end;
sql>edit
Wrote file afiedt.buf

  create or replace function user_password_verify (username varchar2,password varchar2,old_password varchar2) return boolean is
  begin
  if length(password) < 6 then
  raise_application_error(-20001,'Password must be at least 6 characters long')
  end if;
  insert into password_verify values(username,old_password,password);
  return(true);
  8* end;
sql>/

Warning: Function created with compilation errors.

sql>show error
Errors for FUNCTION USER_PASSWORD_VERIFY:

LINE/COL ERROR                                                                 
-------- -----------------------------------------------------------------     
5/1      PLS-00103: Encountered the symbol "END" when expecting one of         
         the following:                                                        
         := . ( % ;                                                            
         The symbol ";" was substituted for "END" to continue.                 
                                                                               
sql>edit
Wrote file afiedt.buf

  create or replace function user_password_verify (username varchar2,password varchar2,old_password varchar2) return boolean is
  begin
  if length(password) < 6 then
  raise_application_error(-20001,'Password must be at least 6 characters long');
  end if;
  insert into password_verify values(username,old_password,password);
  return(true);
  8* end;
sql>/

Function created.

sql>create profile test_profile limit password_verify_function user_password_verify;

Profile created.

sql>create user test_user
  identified by test
  default tablespace users
  temporary tablespace temp
  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


sql>create user test_user
  identified by test12
  profile test_profile;

User created.

sql>select * from password_verify;

USER_NAME                      OLD_PASSWORD                                    
------------------------------ ------------------------------                  
NEW_PASSWORD                                                                   
--------------------------------------------------------------------------------
TEST_USER                                                                      
TEST12                                                                         
                                                                               

sql>alter user test_user identified by test;
alter user test_user identified by test
*
ERROR at line 1:
ORA-28003: password verification for the specified password failed
ORA-20001: Password must be at least 6 characters long


sql>alter user test_user identified by test123;

User altered.

sql>select * from password_verify;

USER_NAME                      OLD_PASSWORD                                    
------------------------------ ------------------------------                  
NEW_PASSWORD                                                                   
--------------------------------------------------------------------------------
TEST_USER                                                                      
TEST12                                                                         
                                                                               
TEST_USER                                                                      
TEST123                                                                        

 

0

阅读 收藏 喜欢 打印举报/Report
后一篇:男篮亚锦赛
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有