maoj2008 发表于 2011-12-22 08:54

Oracle密码管理(Password Management使用utlpwdmg.sql)

<div id="blog_text" class="cnt"><p><font size="2">使用脚本utlpwdmg.sql可以方便地启动数据库的密码管理。该脚本位于$ORACLE_HOME/rdbms/admin目录下。</font></p>
<p><font size="2"><strong>启动密码管理以前:</strong></font></p>
<p><font size="2">SQL&gt; <font color="#0000ff">select * from v$version;<br>
</font>BANNER<br>
----------------------------------------------------------------<br>
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod<br>
PL/SQL Release 10.2.0.1.0 - Production<br>
CORE&nbsp;&nbsp;&nbsp;10.2.0.1.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Production<br>
TNS for Linux: Version 10.2.0.1.0 - Production<br>
NLSRTL Version 10.2.0.1.0 - Production</font></p>
<p><font size="2">SQL&gt; <font color="#0000ff">select * from dba_profiles where resource_type='PASSWORD';<br>
</font>PROFILE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE LIMIT<br>
------------------------------ -------------------------------- -------- ----------------------------------------<br>
DEFAULT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FAILED_LOGIN_ATTEMPTS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PASSWORD <font color="#ff0000">10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nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PASSWORD_LOCK_TIME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PASSWORD UNLIMITED<br>
DEFAULT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PASSWORD_GRACE_TIME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PASSWORD UNLIMITED</font></p>
<p><font size="2"><strong>启用密码管理:</strong></font></p>
<p><font size="2">SQL&gt; <font color="#0000ff">@?/rdbms/admin/utlpwdmg.sql</font></font></p>
<p><font size="2">Function created</font></p>
<p><font size="2">Profile altered</font></p>
<p><font size="2"><strong>启动后:</strong></font></p>
<p><font size="2">SQL&gt; <font color="#0000ff">select * from dba_profiles where resource_type='PASSWORD';</font></font></p>
<p><font size="2">PROFILE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE LIMIT<br>
------------------------------ -------------------------------- -------- ----------------------------------------<br>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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PASSWORD_VERIFY_FUNCTION&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PASSWORD VERIFY_FUNCTION<br>
DEFAULT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PASSWORD_LOCK_TIME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PASSWORD .0006<br>
DEFAULT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PASSWORD_GRACE_TIME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PASSWORD 10<br>
</font></p>
<p><font size="2">如果新设定的密码不符合复杂性检验规则,就会报错。例如:</font></p>
<p><font size="2">SQL&gt; alter user lh identified by lh;</font></p>
<p><font size="2">alter user lh identified by lh</font></p>
<p><font size="2">ORA-28003: password verification for the specified password failed<br>
ORA-20001: Password same as or similar to user</font></p>
<p><font size="2"><strong>取消密码管理:<br>
</strong></font><font size="2"><br>
SQL&gt;alter profile DEFAULT limit &lt;password_parameter&gt; unlimited;<br>
如:<br>
SQL&gt;<font color="#0000ff">alter profile DEFAULT limit password_reuse_time unlimited;<br>
</font><br>
<strong>停止密码检验函数:</strong><br>
<br>
SQL&gt;<font color="#0000ff">alter profile DEFAULT limit password_verify_function null;</font></font></p>
<p><font size="2">熟悉utlpwdmg.sql脚本有助我们更深入了解oracle密码检查机制。我们可以修改或自定义密码检验函数。</font></p>
<p><font size="2">附utlpwdmg.sql脚本内容(红色自己是我修改的):</font></p>
<p><font size="2">Rem<br>
Rem $Header: utlpwdmg.sql 31-aug-2000.11:00:47 nireland Exp $<br>
Rem<br>
Rem utlpwdmg.sql<br>
Rem<br>
Rem Copyright (c) Oracle Corporation 1996, 2000. All Rights Reserved.<br>
Rem<br>
Rem&nbsp;&nbsp;&nbsp;NAME<br>
Rem&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;utlpwdmg.sql - script for Default Password Resource Limits<br>
Rem<br>
Rem&nbsp;&nbsp;&nbsp;DESCRIPTION<br>
Rem&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This is a script for enabling the password management features<br>
Rem&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;by setting the default password resource limits.<br>
Rem<br>
Rem&nbsp;&nbsp;&nbsp;NOTES<br>
Rem&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This file contains a function for minimum checking of password<br>
Rem&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;complexity. This is more of a sample function that the customer<br>
Rem&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;can use to develop the function for actual complexity checks that the<br>
Rem&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;customer wants to make on the new password.<br>
Rem<br>
Rem&nbsp;&nbsp;&nbsp;MODIFIED&nbsp;&nbsp;(MM/DD/YY)<br>
Rem&nbsp;&nbsp;&nbsp;nireland&nbsp;&nbsp;&nbsp;08/31/00 - Improve check for username=password. #1390553<br>
Rem&nbsp;&nbsp;&nbsp;nireland&nbsp;&nbsp;&nbsp;06/28/00 - Fix null old password test. #1341892<br>
Rem&nbsp;&nbsp;&nbsp;asurpur&nbsp;&nbsp;&nbsp;&nbsp;04/17/97 - Fix for bug479763<br>
Rem&nbsp;&nbsp;&nbsp;asurpur&nbsp;&nbsp;&nbsp;&nbsp;12/12/96 - Changing the name of password_verify_function<br>
Rem&nbsp;&nbsp;&nbsp;asurpur&nbsp;&nbsp;&nbsp;&nbsp;05/30/96 - New script for default password management<br>
Rem&nbsp;&nbsp;&nbsp;asurpur&nbsp;&nbsp;&nbsp;&nbsp;05/30/96 - Created<br>
Rem</font></p>
<p><font size="2">-- This script sets the default password resource parameters<br>
-- This script needs to be run to enable the password features.<br>
-- However the default resource parameters can be changed based<br>
-- on the need.<br>
-- A default password complexity function is also provided.<br>
-- This function makes the minimum complexity checks like<br>
-- the minimum length of the password, password not same as the<br>
-- username, etc. The user may enhance this function according to<br>
-- the need.<br>
-- This function must be created in SYS schema.<br>
-- connect sys/&lt;password&gt; as sysdba before running the script</font></p>
<p><font size="2">CREATE OR REPLACE FUNCTION verify_function<br>
(username varchar2,<br>
password varchar2,<br>
old_password varchar2)<br>
RETURN boolean IS<br>
&nbsp;&nbsp;n boolean;<br>
&nbsp;&nbsp;m integer;<br>
&nbsp;&nbsp;differ integer;<br>
&nbsp;&nbsp;isdigit boolean;<br>
&nbsp;&nbsp;ischar boolean;<br>
&nbsp;&nbsp;ispunct boolean;<br>
&nbsp;&nbsp;digitarray varchar2(20);<br>
&nbsp;&nbsp;punctarray varchar2(25);<br>
&nbsp;&nbsp;chararray varchar2(52);</font></p>
<p><font size="2">BEGIN<br>
&nbsp;&nbsp;digitarray:= '0123456789';<br>
&nbsp;&nbsp;chararray:= 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';<br>
&nbsp;&nbsp;punctarray:='!"#$%&amp;()``*+,-/:;&lt;=&gt;?_';</font></p>
<p><font size="2">&nbsp;&nbsp;-- Check if the password is same as the username<br>
&nbsp;&nbsp;IF NLS_LOWER(password) = NLS_LOWER(username) THEN<br>
&nbsp;&nbsp;&nbsp;&nbsp;raise_application_error(-20001, 'Password same as or similar to user');<br>
&nbsp;&nbsp;END IF;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;-- Check for the minimum length of the password<br>
<font color="#ff0000">&nbsp;&nbsp;-- wangnc modified,2008-9-25 15:11:30,change 4 to 16.<br>
</font>&nbsp;&nbsp;IF length(password) &lt; <font color="#ff0000">16</font> THEN<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise_application_error(-20002, 'Password length less than <font color="#ff0000">16</font><font color="#000000">');<br>
&nbsp;&nbsp;END IF;</font></font></p>
<p><font size="2">&nbsp;&nbsp;-- Check if the password is too simple. A dictionary of words may be<br>
&nbsp;&nbsp;-- maintained and a check may be made so as not to allow the words<br>
&nbsp;&nbsp;-- that are too simple for the password.<br>
&nbsp;&nbsp;<font color="#ff0000">-- wangnc modified,2008-9-25 15:12:17,add 'dba', 'manager', 'tiger'<br>
</font>&nbsp;&nbsp;IF NLS_LOWER(password) IN ('welcome', 'database', 'account', 'user', 'password', 'oracle', 'computer', 'abcd', <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff0000">'dba', 'manager', 'tiger'</font>) THEN<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise_application_error(-20002, 'Password too simple');<br>
&nbsp;&nbsp;END IF;</font></p>
<p><font size="2">&nbsp;&nbsp;-- Check if the password contains at least one letter, one digit and one<br>
&nbsp;&nbsp;-- punctuation mark.<br>
&nbsp;&nbsp;-- 1. Check for the digit<br>
&nbsp;&nbsp;isdigit:=FALSE;<br>
&nbsp;&nbsp;m := length(password);<br>
&nbsp;&nbsp;FOR i IN 1..10 LOOP<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FOR j IN 1..m LOOP<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IF substr(password,j,1) = substr(digitarray,i,1) THEN<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isdigit:=TRUE;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GOTO findchar;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END IF;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END LOOP;<br>
&nbsp;&nbsp;END LOOP;<br>
&nbsp;&nbsp;IF isdigit = FALSE THEN<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise_application_error(-20003, 'Password should contain at least one digit, one character and one punctuation');<br>
&nbsp;&nbsp;END IF;<br>
&nbsp;&nbsp;-- 2. Check for the character<br>
&nbsp;&nbsp;&lt;&lt;findchar&gt;&gt;<br>
&nbsp;&nbsp;ischar:=FALSE;<br>
&nbsp;&nbsp;FOR i IN 1..length(chararray) LOOP<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FOR j IN 1..m LOOP<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IF substr(password,j,1) = substr(chararray,i,1) THEN<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ischar:=TRUE;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GOTO findpunct;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END IF;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END LOOP;<br>
&nbsp;&nbsp;END LOOP;<br>
&nbsp;&nbsp;IF ischar = FALSE THEN<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise_application_error(-20003, 'Password should contain at least one \<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;digit, one character and one punctuation');<br>
&nbsp;&nbsp;END IF;<br>
&nbsp;&nbsp;-- 3. Check for the punctuation<br>
&nbsp;&nbsp;&lt;&lt;findpunct&gt;&gt;<br>
&nbsp;&nbsp;ispunct:=FALSE;<br>
&nbsp;&nbsp;FOR i IN 1..length(punctarray) LOOP<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FOR j IN 1..m LOOP<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IF substr(password,j,1) = substr(punctarray,i,1) THEN<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ispunct:=TRUE;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GOTO endsearch;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END IF;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END LOOP;<br>
&nbsp;&nbsp;END LOOP;<br>
&nbsp;&nbsp;IF ispunct = FALSE THEN<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise_application_error(-20003, 'Password should contain at least one \<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;digit, one character and one punctuation');<br>
&nbsp;&nbsp;END IF;</font></p>
<p><font size="2">&nbsp;&nbsp;&lt;&lt;endsearch&gt;&gt;<br>
&nbsp;&nbsp;-- Check if the password differs from the previous password by at least<br>
&nbsp;&nbsp;-- 3 letters<br>
&nbsp;&nbsp;IF old_password IS NOT NULL THEN<br>
&nbsp;&nbsp;&nbsp;&nbsp;differ := length(old_password) - length(password);</font></p>
<p><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;IF abs(differ) &lt; 3 THEN<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IF length(password) &lt; length(old_password) THEN<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m := length(password);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ELSE<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m := length(old_password);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END IF;</font></p>
<p><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;differ := abs(differ);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FOR i IN 1..m LOOP<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IF substr(password,i,1) != substr(old_password,i,1) THEN<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;differ := differ + 1;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END IF;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END LOOP;</font></p>
<p><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IF differ &lt; 3 THEN<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raise_application_error(-20004, 'Password should differ by at \<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;least 3 characters');<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END IF;<br>
&nbsp;&nbsp;&nbsp;&nbsp;END IF;<br>
&nbsp;&nbsp;END IF;<br>
&nbsp;&nbsp;-- Everything is fine; return TRUE ;<br>
&nbsp;&nbsp;RETURN(TRUE);<br>
END;<br>
/</font></p>
<p><font size="2"><br>
-- This script alters the default parameters for Password Management<br>
-- This means that all the users on the system have Password Management<br>
-- enabled and set to the following values unless another profile is<br>
-- created with parameter values set to different value or UNLIMITED<br>
-- is created and assigned to the user.</font></p>
<p><font color="#ff0000" size="2">/*<br>
PASSWORD_LIFE_TIME 90 --用于指定口令有效期<br>
PASSWORD_GRACE_TIME 10 --用于指定口令宽限期(为了强制用户定期改变口令,以上二者必须同时设置.)<br>
PASSWORD_REUSE_TIME 1800 --用于指定口令可重用时间.<br>
PASSWORD_REUSE_MAX UNLIMITED --用于指定在重用口令之前口令需要改变的次数.(需要主要,使用口令历史选项时,只能使用以上两种其中的一个选项.并将另一个选项设置为UNLIMITED.)<br>
FAILED_LOGIN_ATTEMPTS 3 --用于指定连续登陆的最大失败次数.<br>
PASSWORD_LOCK_TIME 1/1440 --用于指定帐户被锁定的天数.<br>
PASSWORD_VERIFY_FUNCTION verify_function; --如果要禁用口令校验函数,可以将PASSWORD_VERIFY_FUNCTION选项设置为NULL.<br>
*/</font></p>
<p><font size="2">ALTER PROFILE DEFAULT LIMIT<br>
PASSWORD_LIFE_TIME 90 <br>
</font><font size="2">PASSWORD_GRACE_TIME 10 <font color="#ff0000"><br>
</font>PASSWORD_REUSE_TIME 1800 <br>
PASSWORD_REUSE_MAX UNLIMITED <font color="#ff0000"><br>
</font>FAILED_LOGIN_ATTEMPTS 3 <font color="#ff0000"><br>
</font>PASSWORD_LOCK_TIME 1/1440 <font color="#ff0000"><br>
</font>PASSWORD_VERIFY_FUNCTION verify_function; </font></p>
<p> </p>
<p><font size="2">--End--</font></p><p><br></p><p><font size="2">------------</font></p><h2><span class="mw-headline">What is Profile </span></h2>
<p>A <b>profile</b> is a database object - a named set of resource limits to:
</p>
<ul><li> Restrict database usage by a system user – profiles restrict
users from performing operations that exceed reasonable resource
utilization.Examples of resources that need to be managed:
</li></ul>
<ul><li><ul><li> Disk storage space.
</li><li> I/O bandwidth to run queries.
</li><li> CPU power.
</li><li> Connect time.
</li></ul>
</li></ul>
<ul><li> Enforce password practices – how user passwords are created, reused, and validated.
</li></ul>
<ul><li> Profiles are assigned to users as part of the CREATE USER or ALTER USER commands.
</li></ul>
<ul><li><ul><li> User accounts can have only a single profile.
</li><li> A default profile can be created – a default already exists
within Oracle named DEFAULT – it is applied to any user not assigned
another profile.
</li><li> Assigning a new profile to a user account supersedes any earlier profile.
</li><li> Profiles cannot be assigned to roles or other profiles.
</li></ul>
</li></ul>
<p>Here are some system privileges for <b>PROFILE</b>.
</p>
<ul><li><ul><li> alter profile
</li><li> create profile
</li><li> drop profile
</li></ul>
</li></ul>
<a name="Benefits_of_Profile"></a><h2><span class="editsection"></span><span class="mw-headline"> Benefits of Profile </span></h2>
<p>You can enforce a limit on resource utilization using resource limit parameters
Also you can maintain database secutiry by using password management feature
</p>
<a name="Resource___Parameters"></a><h2><span class="editsection"></span><span class="mw-headline">Resource   Parameters </span></h2>
<p><b>•        SESSIONS_PER_USER</b>
</p><p>Specify the number of concurrent sessions to which you want to limit the user.
</p><p><b>•        CPU_PER_SESSION</b>
</p><p>Specify the CPU time limit for a session, expressed in hundredth of seconds.
</p><p><b>•        CPU_PER_CALL</b>
</p><p>Specify the CPU time limit for a call (a parse, execute, or fetch), expressed in hundredths of seconds.
</p><p><b>•        CONNECT_TIME</b>
</p><p>Specify the total elapsed time limit for a session, expressed in minutes.
</p><p><b>•        IDLE_TIME</b>
</p><p>Specify the permitted periods of continuous inactive time during a
session, expressed in minutes. Long-running queries and other
operations are not subject to this limit.
</p><p><b>•        LOGICAL_READS_PER_SESSION</b>
</p><p>Specify the permitted number of data blocks read in a session, including blocks read from memory and disk.
</p><p><b>•        LOGICAL_READS_PER_CALL</b>
</p><p>Specify the permitted the number of data blocks read for a call to process a SQL statement (a parse, execute, or fetch).
</p><p><b>•        PRIVATE_SGA</b>
</p><p>Specify the amount of private space a session can allocate in the
shared pool of the system global area (SGA), expressed in bytes.
</p><p><b>•        COMPOSITE_LIMIT</b>
</p><p>Specify the total resource cost for a session, expressed in
service units. Oracle Database calculates the total service units as a
weighted sum of CPU_PER_SESSION, CONNECT_TIME,
LOGICAL_READS_PER_SESSION, and PRIVATE_SGA.
</p>
<a name="Creating____Profile"></a><h2><span class="editsection"></span><span class="mw-headline"> Creating    Profile </span></h2>
<p>Profiles only take effect when resource limits are "turned on" for the database as a whole.
</p><p>• Specify the RESOURCE_LIMIT initialization parameter.
</p><p><b>RESOURCE_LIMIT = TRUE</b>
</p><p>Let check the parameter value.
</p>
<pre>SQL&gt; show parameter resource_limit<br>NAME                                 TYPE      VALUE<br>------------------------------------ ----------- ---------<br>resource_limit                     boolean   FALSE<br></pre>
<p>Its mean resource limit is off,we ist have to enable it.
</p><p>• Use the ALTER SYSTEM statement to turn on resource limits.
</p>
<pre>SQL&gt; ALTER SYSTEM SET RESOURCE_LIMIT = TRUE;<br>System altered.<br>SQL&gt; show parameter resource_limit<br>NAME                                 TYPE      VALUE<br>------------------------------------ ----------- ---------<br>resource_limit                     boolean   TRUE<br></pre>
<p>• Resource limit specifications pertaining to passwords are always in effect.
</p><p>Now I'm going to create a profile with the name <b>my_profile</b>.
</p>
<pre>SQL&gt; CREATE PROFILE my_profile LIMIT<br>       SESSIONS_PER_USER 2<br>       IDLE_TIME 5<br>       CONNECT_TIME 10;<br></pre>
<p>Profile created.
</p><p><br>
In the above example i created simple profile which will handle
</p>
<pre>SESSIONS_PER_USER&lt;&lt;&lt;I'm able to open 2 sessions concurrent<br>IDLE_TIME          &lt;&lt;&lt;My session will be terminate automatically after the time specified for this parameter.<br>CONNECT_TIME       &lt;&lt;&lt;It will keep me onlineuntil the value of this parameter.<br></pre>
<p><br>
<b>NOTE:</b>
</p><p>Both parameters take values in min.
</p><p>Now I'm creating a test user to check the functionality of this profile.
</p>
<pre>SQL&gt; create user Michel identified by michel<br>    default tablespace users<br>    temporary tablespace temp;<br>User created.<br></pre>
<p><br>
</p>
<pre>SQL&gt; alter user Michel profile my_profile;<br>User altered.<br></pre>
<p>With the above statement i assigned the profile <b>my_profile</b> to user <b>Michel</b>.
</p><p>Let see how our profile will work.
</p><p>I already opened 2 sessions with the user name Michel but when i tried for third session it thorwed this error.
</p>
<pre>sqlplus Michel<br>SQL*Plus: Release 11.1.0.6.0 - Production on Mon Nov 26 15:57:23 2007<br>Copyright (c) 1982, 2007, Oracle.All rights reserved.<br>Enter password:<br>ERROR:<br><b>ORA-02391: exceeded simultaneous SESSIONS_PER_USER limit</b><br></pre>
<p>
You noticed when i tried to open third session it gave me error.
</p><p>Lets go to 2nd step IDLE_TIME.Here we go again
</p>
<pre>SQL&gt; select * from tab;<br>select * from tab<br>*<br>ERROR at line 1:<br><b>ORA-02396: exceeded maximum idle time, please connect again</b><br></pre>
<p>Because i was idle more than 5 min so thats why Oracle server kill mine session.
</p><p>We can check the resource parameter of our profile by querying <b>DBA_PROFILES</b>.
</p>
<pre>SQL&gt; select * from dba_profiles<br>   where profile='MY_PROFILE';<br>PROFILE                        RESOURCE_NAME                  RESOURCE LIMIT<br>------------------------------ -------------------------------- -------- ------<br>---------------------------------<br>MY_PROFILE                     COMPOSITE_LIMIT                  KERNEL   DEFAUL<br>MY_PROFILE                     SESSIONS_PER_USER                KERNEL   2<br>MY_PROFILE                     IDLE_TIME                        KERNEL   5<br>MY_PROFILE                     CONNECT_TIME                     KERNEL   10<br>.<br>.<br>.<br></pre>
<a name="Assigning___Profile"></a><h2><span class="editsection"></span><span class="mw-headline">Assigning   Profile </span></h2>
<p>Profile can be assign in two ways either during <b>USER</b> creation or by using <b>ALTER</b> statement.
</p><p><b>Case 1:</b>
</p>
<pre>SQL&gt; create user orafaq identified by pass <b>profile my_profile</b>;<br>User created.<br></pre>
<p>We can check it by using this query.
</p>
<pre>SQL&gt; select username,profile<br>   from dba_users<br>   where username='ORAFAQ';<br></pre>
<pre>USERNAME                     PROFILE<br>------------------------------ --------------<br>ORAFAQ                         MY_PROFILE<br></pre>
<p><b>CASE 2:</b>
</p>
<pre>SQL&gt; drop user orafaq cascade;<br>User dropped.<br>SQL&gt; create user orafaq identified by pass;<br>User created.<br>SQL&gt; alter user orafaq profile my_profile;<br>User altered.<br></pre>
<a name="Altering____Profile"></a><h2><span class="editsection"></span> <span class="mw-headline">Altering    Profile </span></h2>
<p>Profiles can be altered with the ALTER PROFILE command.
•        A DBA must have the ALTER PROFILE system privilege to use this
command.
•        When a profile limit is adjusted, the new setting overrides the
previous setting for the limit, but these changes do not affect current
sessions in process.See the example below
</p><p><br>
SQL&gt;         ALTER PROFILE accountant LIMIT
        CPU_PER_CALL default
        LOGICAL_READS_PER_SESSION 20000
        SESSIONS_PER_USER 1;
</p>
<a name="Dropping____Profile"></a><h2><span class="editsection"></span><span class="mw-headline"> Dropping    Profile </span></h2>
<p>Profiles no longer required can be dropped with the DROP PROFILE
command.
•        The DEFAULT profile cannot be dropped.
•        The CASCADE clause revokes the profile from any user account to which
it was assigned – the CASCADE clause MUST BE USED if the profile has
been assigned to any user account.
•        When a profile is dropped, any user account with that profile is
reassigned the DEFAULT profile. See examples below:
</p><p>SQL&gt; DROP PROFILE accountant;
</p><p>ERROR at line 1:
</p><p>ORA-02382: profile ACCOUNTANT has users assigned, cannot drop without CASCADE
</p><p>SQL&gt; DROP PROFILE accountant CASCADE;
</p><p><br>
SQL&gt;         SELECT username, profile FROM dba_users
        WHERE username = 'DBUSER1';
•        Changes that result from dropping a profile only apply to sessions
that are created after the change – current sessions are not modified.
</p></div>
               
               
               
页: [1]
查看完整版本: Oracle密码管理(Password Management使用utlpwdmg.sql)