Oracle saving users passwords before EXPORT IMPORT 10g and 11g

When you import an older dump file into a newer instance you will lose users and/or revert their passwords to older password (from say 90 days ago). This can be a headache. So the answer is, save the passwords from the current database by capturing the users and their hashes, then IMPORT and put the hashes back into the restored database. Here's how in 10g:

 

--before export 
select 'ALTER USER ' || USERNAME || ' IDENTIFIED BY TEST;' FROM DBA_USERS;

-- do the IMPORT

-- restore passwords
spool recovermypasswords.sql
select 'ALTER USER ' || USERNAME || ' IDENTIFIED BY VALUES '|| CHR(39) || PASSWORD || CHR(39) || CHR(59) FROM DBA_USERS;

-- run the script
@recovermypasswords.sql

-- now delete the file, bad news to leave this lying around
!rm recovermypasswords.sql

Now in 11g the password field in DBA_USERS is blank, and the password hash is stored over in SYS.USER$