在其他答案的状态下,适当更改用户的配置文件(例如,“ DEFAULT”配置文件)将产生密码,密码一旦设置就永远不会过期。
但是,正如一位评论者所指出的那样,在配置文件的旧值下设置的密码可能已经过期,并且(如果在配置文件的指定宽限期之后)该帐户已被锁定。
具有锁定帐户的过期密码的解决方案(如答复注释中所述)是使用一种版本的ALTER USER命令:
ALTER USER xyz_user ACCOUNT UNLOCK;
但是,unlock命令仅适用于实际上已锁定帐户的帐户,不适用于处于宽限期的帐户,即密码已过期但尚未锁定的帐户。对于这些帐户,必须使用另一版本的ALTER USER命令重置密码:
ALTER USER xyz_user IDENTIFIED BY new_password;
下面是一些SQL * Plus脚本,特权用户(例如,用户'SYS')可以使用该脚本将用户密码重置为存储在数据库中的当前现有哈希值。
编辑:较旧的Oracle版本将密码或密码哈希存储在pword列中,较新的Oracle版本将密码哈希存储在spare4列中。下面的脚本已更改为收集pword和spare4列,但要使用spare4列来重置用户帐户;根据需要进行修改。
REM Tell SQL*Plus to show before and after versions of variable substitutions.
SET VERIFY ON
SHOW VERIFY
REM Tell SQL*Plus to use the ampersand '&' to indicate variables in substitution/expansion.
SET DEFINE '&'
SHOW DEFINE
REM Specify in a SQL*Plus variable the account to 'reset'.
REM Note that user names are case sensitive in recent versions of Oracle.
REM DEFINE USER_NAME = 'xyz_user'
REM Show the status of the account before reset.
SELECT
ACCOUNT_STATUS,
TO_CHAR(LOCK_DATE, 'YYYY-MM-DD HH24:MI:SS') AS LOCK_DATE,
TO_CHAR(EXPIRY_DATE, 'YYYY-MM-DD HH24:MI:SS') AS EXPIRY_DATE
FROM
DBA_USERS
WHERE
USERNAME = '&USER_NAME';
REM Create SQL*Plus variable to hold the existing values of the password and spare4 columns.
DEFINE OLD_SPARE4 = ""
DEFINE OLD_PASSWORD = ""
REM Tell SQL*Plus where to store the values to be selected with SQL.
REM Note that the password hash value is stored in spare4 column in recent versions of Oracle,
REM and in the password column in older versions of Oracle.
COLUMN SPARE4HASH NEW_VALUE OLD_SPARE4
COLUMN PWORDHASH NEW_VALUE OLD_PASSWORD
REM Select the old spare4 and password columns as delimited strings
SELECT
'''' || SPARE4 || '''' AS SPARE4HASH,
'''' || PASSWORD || '''' AS PWORDHASH
FROM
SYS.USER$
WHERE
NAME = '&USER_NAME';
REM Show the contents of the SQL*Plus variables
DEFINE OLD_SPARE4
DEFINE OLD_PASSWORD
REM Reset the password - Older versions of Oracle (e.g. Oracle 10g and older)
REM ALTER USER &USER_NAME IDENTIFIED BY VALUES &OLD_PASSWORD;
REM Reset the password - Newer versions of Oracle (e.g. Oracle 11g and newer)
ALTER USER &USER_NAME IDENTIFIED BY VALUES &OLD_SPARE4;
REM Show the status of the account after reset
SELECT
ACCOUNT_STATUS,
TO_CHAR(LOCK_DATE, 'YYYY-MM-DD HH24:MI:SS') AS LOCK_DATE,
TO_CHAR(EXPIRY_DATE, 'YYYY-MM-DD HH24:MI:SS') AS EXPIRY_DATE
FROM
DBA_USERS
WHERE
USERNAME = '&USER_NAME';