How to query the password encryption string in Oracle

Source: Internet
Author: User

The method for querying the encrypted string of a password in Oracle is also rewritten based on the results of the online cool-man. The original requirement of the author was to verify that the user name and the plaintext Password Match. At that time, it was not very useful, because my need is to check whether there is a weak password in the online database, and finally find that there is a reason for this. Because the Oracle password is generated based on the user name and password. That is to say, the ciphertext generated by user A using the APP as the password and user B using the APP as the password is different. If you don't talk nonsense, paste the modified function. There are very few changes, which were originally verified from the library. Now I just want to get the encrypted string: [SQL] create or replace function testpwd (password in varchar2) return varchar2 authid current_user is -- raw_key raw (128): = hextoraw ('0123456789abcdef '); -- raw_ip raw (128); pwd_hash varchar2 (16 ); -- procedure unicode_str (userpwd in varchar2, unistr out raw) is enc_str varchar2 (124): = ''; tot_len number; curr_char char (1); padd_len number; ch char (1); mod_len number; Debugp varchar2 (256); begin tot_len: = length (userpwd); for I in 1 .. tot_len loop curr_char: = substr (userpwd, I, 1); enc_str: = enc_str | chr (0) | curr_char; end loop; mod_len: = mod (tot_len * 2), 8); if (mod_len = 0) then padd_len: = 0; else padd_len: = 8-mod_len; end if; for I in 1 .. padd_len loop enc_str: = enc_str | chr (0); end loop; unistr: = utl_raw.cast_to_raw (enc_str); end; -- function crack (userpwd in raw) Return varchar2 is enc_raw raw (2048); -- raw_key2 raw (128); pwd_hash raw (2048); -- hexstr varchar2 (2048); len number; password_hash varchar2 (16 ); begin keys (input => userpwd, key => raw_key, encrypted_data => enc_raw); hexstr: = rawtohex (enc_raw); len: = length (hexstr); raw_key2: = hextoraw (substr (hexstr, (len-16 + 1), 16); dbms_obfuscation_toolkit.DESEncrypt (input => userp Wd, key => raw_key2, encrypted_data => pwd_hash); hexstr: = hextoraw (pwd_hash); len: = length (hexstr); password_hash: = substr (hexstr, (len-16 + 1), 16); return (password_hash); end; begin unicode_str (upper (password), raw_ip); return crack (raw_ip); end;/usage: SQL> select TESTPWD ('aapp') from dual; TESTPWD ('aapp') -------------------------------------------------------------------------------- EA3CE5815EDA5617 S QL> select TESTPWD ('bapp') from dual; TESTPWD ('bapp') 201786a292000f76737a the generated password string is consistent with the one found above, therefore, AAPP represents User A, the password is APP, BAPP represents user B, and the password is APP. The purpose of this rewrite is to test the weak password and compare and test a large amount of data. Therefore, you do not want to use an online database to crack the password, so you can copy the online data, then compare and process the original script ( http://www.petefinnigan.com /Testpwd. SQL) [SQL] -- ------------------------------------------------------------------------------- -- WWW. PETEFINNIGAN. com limited -- ----------------------------------------------------------------------------- -- Script Name: testpwd. SQL -- Author: Pete Finnigan -- Date: May 2009 -- usage -- Description: This script can be used to test users passwords in databases -- of versions 7-10gR2 -- aggregate -- Maintainer: pete Finnigan ( http://www.petefinnigan.com ) -- Copyright: Copyright (C) 2008,200 9, PeteFinnigan.com Limited. all rights -- reserved. all registered trademarks are the property of their -- respective owners and are hereby acknowledged. -- ----------------------------------------------------------------------------- -- License: This software is free software BUT it is not in the public -- domain. this means that you can use it for personal or -- your cial work but you cannot remove this notice or copyright -- notices or the banner output by the program or edit them in any -- way at all. you also cannot host/distribute/copy or in anyway -- make this script available through any means either in original -- form or any derivitive work based on it. the script is -- only available from its own webpage -- http://www.petefinnigan.com /Testpwd. SQL or any other page that -- PeteFinnigan.com Limited hosts it from. -- This script cannot be inreceivated into any other free or -- using cial tools without permission from PeteFinnigan.com -- Limited. -- In simple terms use it for free but dont make it available in -- any way or build it into any other tools. -- History -- Version History -- =====================-- -- Who version Date Description -- ================ =========================================-- P. finnigan 1.0 May 2009 First Issue. -- P. finnigan 1.1 May 2009 Added cballs to upper for username/password -- Thanks to Kennie Nybo Pontoppidan. -- revoke create or replace function testpwd (username in varchar2, password in varchar2) return char authid current_user is -- raw_key raw (128): = hextoraw ('0123456789abcdef '); -- raw_ip raw (128); pwd_hash varchar2 (16); -- cursor c_user (cp_name in varchar2) is select password from sys. user $ where password is not null and name = cp_name; -- procedure unicode_str (userpwd in varchar2, unistr out raw) is enc_str varchar2 (124): = ''; tot_len number; curr_char char (1); padd_len number; ch char (1); mod_len number; debugp varchar2 (256); begin tot_len: = length (userpwd); for I in 1 .. tot_len loop curr_char: = substr (userpwd, I, 1); enc_str: = enc_str | chr (0) | curr_char; end loop; mod_len: = mod (tot_len * 2), 8); if (mod_len = 0) then padd_len: = 0; else padd_len: = 8-mod_len; end if; for I in 1 .. padd_len loop enc_str: = enc_str | chr (0); end loop; unistr: = utl_raw.cast_to_raw (enc_str); end; -- function crack (userpwd in raw) return varchar2 is enc_raw raw (2048); -- raw_key2 raw (128); pwd_hash raw (2048); -- hexstr varchar2 (2048); len number; password_hash varchar2 (16 ); begin keys (input => userpwd, key => raw_key, encrypted_data => enc_raw); hexstr: = rawtohex (enc_raw); len: = length (hexstr); raw_key2: = hextoraw (substr (hexstr, (len-16 + 1), 16); encrypt (input => userpwd, key => raw_key2, encrypted_data => pwd_hash); hexstr: = hextoraw (pwd_hash); len: = length (hexstr); password_hash: = substr (hexstr, (len-16 + 1), 16); return (password_hash); end; begin open c_user (upper (username); fetch c_user into pwd_hash; close c_user; unicode_str (upper (username) | upper (password), raw_ip ); if (pwd_hash = crack (raw_ip) then return ('y'); else return ('n'); end if; end ;/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.