Restore database user history account password

1. 用户状态

select * from user_astatus_map;

select * from user_astatus_map;
   STATUS# STATUS
---------- --------------------------------
          OPEN
          EXPIRED
          EXPIRED(GRACE)
     4     LOCKED(TIMED)
          LOCKED
          EXPIRED & LOCKED(TIMED)
          EXPIRED(GRACE) & LOCKED(TIMED)
          EXPIRED & LOCKED
         EXPIRED(GRACE) & LOCKED

2.  password_versions

2.1)在oracle 10g, 密码记录在sys.user$.PASSWORD列,其长度为16字符,且不区分大小写;

2.2)在oracle 11g版本后,其复杂度得到了加强,将密码同时写入到sys.user$.spare4列,并且sys.user$.spare4对大小敏感。

2.3)dba_users.password_versions的优先级大于sec_case_sensitive_logon参数,11g默认为true。

3. 下面通过语句进行刷密码操作

3.1)创建序列

 start  nomaxvalue nocycle nocache;

3.2)创建操作记录表

create table tb_refpwd_log(
  id number not null,                        -- 引用seq_refpwd.nextval
  oper_time date,                            -- 记录操作时间
  oper_command )                -- 记录操作命令内容
);

3.3)执行语句

declare
  v_datetime ) := to_char(sysdate, 'yyyymmddHH24MI');
  v_tbname   ) := trim(concat('tb_userpwd_', v_datetime)); -- 备份表名称
  v_pf_sql   ) := 'create profile temp_profile limit PASSWORD_REUSE_MAX UNLIMITED PASSWORD_REUSE_TIME UNLIMITED'; -- 构造创建profile语句
  v_sql      );
  TYPE RECORD_TYPE_USERS IS RECORD(
    v_username sys.user$.name%TYPE,
    v_user_pwd ),
    v_profile  ),
    v_status   sys.user$.ASTATUS%TYPE);
  user_rec RECORD_TYPE_USERS;
  cursor c_pwd_cursor is
    select t2.name,
           case trim(t1.password_versions)
             when '10G' then
              t2.password
             else
              nvl(t2.spare4, t2.password)
           end,
           t1.profile,
           t2.astatus
      from sys.dba_users t1, sys.user$ t2
     where t1.user_id = t2.user#
       , , , , , );
  invalid_option EXCEPTION;

begin
  -- select to_char(sysdate, 'yyyymmddHH24MI') into v_datetime from dual;
  -- select trim(concat('tb_userpwd_',v_datetime)) into v_tbname from dual;
  select 'create table ' || v_tbname ||
         ' as select name,type#,password,datats#,tempts#,ctime,ptime,exptime,ltime,resource$,astatus,lcount,spare4 from sys.user$ where astatus <> 9'
    into v_sql
    from dual;

  open c_pwd_cursor;
  fetch c_pwd_cursor
    into user_rec;
   then
    -- 1. create unlimited temporary profile
    execute immediate v_pf_sql;
      IF SQL%NOTFOUND THEN
        RAISE invalid_option;
      end IF;
    -- 2. backup user$ tables
    execute immediate v_sql;
      IF SQL%NOTFOUND THEN
        RAISE invalid_option;
      end IF;
  end if;
  while c_pwd_cursor%FOUND LOOP
    -- 3. reflash user password
    /*
    dbms_output.put_line('alter user ' || user_rec.v_username ||
                         ' profile temp_profile');
    dbms_output.put_line('alter user ' || user_rec.v_username ||
                         ' identified by values ' || chr(39) ||
                         user_rec.v_user_pwd || chr(39));
    dbms_output.put_line('alter user ' || user_rec.v_username ||
                         ' profile ' || user_rec.v_profile);
    */
    execute immediate 'alter user ' || user_rec.v_username ||
                      ' profile temp_profile';
    execute immediate 'alter user ' || user_rec.v_username ||
                      ) ||
                      user_rec.v_user_pwd );
    ) ));
    execute immediate 'alter user ' || user_rec.v_username || ' profile ' ||
                      user_rec.v_profile;
    fetch c_pwd_cursor
      into user_rec;
  end loop;
  -- 4. delete temporary profile
  execute immediate 'drop profile temp_profile cascade';
  insert into tb_refpwd_log(id, oper_time, oper_command) values(seq_refpwd.nextval,v_datetime,'drop profile temp_profile cascade');
  commit;
  close c_pwd_cursor;
  EXCEPTION
    when invalid_option then
      , v_datetime, 'invalid opertaion, please check.');
    when others then
      null;
end;
/

4. 结果确认

) cnt
  from (select t1.name, t1.password, t1.spare4
          from sys.user$ t1

        minus
        select t2.name, t2.password, t2.spare4
          from &v_datetime t2
         );

select username, account_status, lock_date, expiry_date, created, profile, password_versions,default_tablespace, temporary_tablespace from dba_users;

Oracle rdbms Brush password的更多相关文章

  1. 由ORACLE:ORA-28001: the password has expired(密码过期)引起ODI资料库连接失败

    今天,连接ODI,出现下面的错误 oracle.odi.core.config.WorkRepositoryResourceFailureException: ODI-10182: 资料档案库访问期间 ...

  2. oracle:the password has expired

    今天在用dbvisualizer登录数据库的时候,报了the password has expired的错误,于是上网查了一下原因,是因为数据库密码过期了,因为默认的是180天. 解决方法: 1)用系 ...

  3. [ORACLE]ORA-28002 The password will expire within 7 days.将不能登录系统

    错误“ORA-28002 The password will expire within 7 days.  Cannot logon to the database“当在进程调度器上运行AE程序可能遇 ...

  4. Oracle密码过期the password has expired解决办法

    oracle 出现the password has expired这个问题,今天突然发现项目访问不了,一查发现用不了,也登不进去, 这个问题由是Oracle11g密码过期的原因导致的 调试Web项目的 ...

  5. ORACLE错误:ORA-28001: the password has expired解决方法

    Oracle提示错误消息ORA-28001: the password has expired,是由于Oracle11G的新特性所致, Oracle11G创建用户时缺省密码过期限制是180天(即6个月 ...

  6. Oracle 11g静默安装简明版

    环境:RHEL 6.5 + Oracle 11.2.0.4 1. 初步处理应答文件 2. 静默安装软件 3. 静默安装监听 4. 静默dbca建库 说明: 本文默认安装软件前的步骤已经设置完毕 如果没 ...

  7. vmware workstation9.0 RHEL5.8 oracle 10g RAC安装指南及问题总结

    一,虚拟机规划 (1)虚拟机:添加三块网卡 eth0 eth1 eth2 ,分别用于内网,心跳,外网RAC1 内网:192.168.1.10/24  心跳:192.168.2.10/24  VIP:1 ...

  8. 使用BBED模拟Oracle数据库坏块

    BBED(OracleBlockBrowerandEDitor Tool),用来直接查看和修改数据文件数据的一个工具,是Oracle一款内部工具,可以直接修改Oracle数据文件块的内容,在一些极端恢 ...

  9. Oracle EBS R12 (12.1.3) Installation Linux(64 bit)

    Oracle EBS R12 (12.1.3) Installation Linux(64 bit) Contents Objective. 3 1 Download & Unzip. 3 D ...

随机推荐

  1. 【游记】Noip2018

    Day -1 Noip还有1天,加油!!! 今天上午就肝一肝树形DP,维护一些玄学差分,和前缀数组什么的吧 下午以及晚上搞一搞记忆化搜索和最朴素的DFS这样子吧. 还要打一打板子也是极有必要的qwq ...

  2. java基础-面向对象的思想

    一.什么是面向对象 面向对象是一种思想,在java中通常我们会说一句话一切事物即对象.而面向对象到底是怎么回事呢?这里我从人们对问题的思考来阐述,人在思考的一个问题的时候比如在解决一个数学问题的时候我 ...

  3. 记一次SQL注入实战

    刚发现漏洞时,我就已经成功实现了注入,因为怕发到网上后被玩坏,一直没有发布.今天去看了看,原网页已经无法访问了,现在发出来应该就没有什么大问题了. 本文仅供学习交流,目的是为了构建更加安全的网络环境! ...

  4. 深入浅出Mybatis技术原理与实战(杨开振)(带详细书签) PDF 下载 高清 完整版+源码

    (杨开振) 源码 IDE eclipse 建表语句也在里面 电子书+源码地址

  5. .net防止SQL注入的一种方式

    首先也要明白一点,什么是SQL注入 所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.具体来说,它是利用现有应用程序,将 ...

  6. AutoMapper在项目中的应用

    一.先说说DTO DTO是个什么东东? DTO(Data Transfer Object)就是数据传输对象,说白了就是一个对象,只不过里边全是数据而已. 为什么要用DTO? 1.DTO更注重数据,对领 ...

  7. C++ 中std::function 、std::bind的使用和lambda的使用

    std::function是可调用对象的包装器:std::bind是将可点用对象和其参数一起进行绑定,且绑定后的结果可以使用std::function对象进行保存,并延迟调用到需要调用的时候: 在C+ ...

  8. Ubuntu14.16.18更新源

    一.源概述 源,可以认为是软件库,使用apt-get install安装的时候,会在源保存的库中进行搜索,因此源(默认源在欧洲)会影响下载速度和资源数量 二.更新源 1.步骤 编辑/etc/apt/s ...

  9. equals与hashcode区别

    哈希码:   hashCode的作用是用来获取哈希码,也可以称作散列码.实际返回值为一个int型数据.用于确定对象在哈希表中的位置. Object中有hashcode方法,也就意味着所有的类都有has ...

  10. 搭建ReactNative时的最普遍的错误—— ":CFBundleIdentifier", Does Not Exist

    报错 ":CFBundleIdentifier", Does Not Exist 今天搭建Reactnative 报错 注意当你第一次搭建RN时,包体下载的都是最新的版本,由于现在 ...