用户名与口令相同使得口令易于记忆和猜测,但口令也容易被破译,因此作为数据库管理员应该及时检查用户的设置,避免用户名与口令相同,消除不安因素。
创建查询子程序:
SQL> create or replace procedure sys.find_the_same as
hex_password varchar2(30);
trans_password varchar2(30);
v_username varchar2(30);
cursor c1 is select username, password from dba_users;
begin
for i in c1 loop
--保存用户最初的口令和用户名,口令以十六进制表示。
hex_password:=i.password;
v_username:=i.username;
--将口令改成用户名,系统将其加密后以十六进制表示。
execute immediate 'alter user' || v_username || 'identified by' || v_username;
--查询修改后的以十六进制表示的用户口令。
select password into trans_password from dba_users where username=v_username;
--比较修改前和修改后的口令。
if trans_password=hex_password then
dbms_output.put_line(v_username);
else
--将口令改回原来的值
execute immediate 'alter user' || v_username || 'identified by values''' || hex_password || '''';
end if;
end loop;
end;