My requirement is to check whether a weak password exists in the online database. I found that there was a reason for this. Because the Oracle password is generated based on the user name and password. That's it.
My requirement is to check whether a weak password exists in the online database. I found that there was a reason for this. Because the Oracle password is generated based on the user name and password. That's it.
The method was rewritten based on the results of the online cool. The original requirement of the author was to verify whether the user name and password match clearly. 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. It turns out to be verified from the database. Now I just want to get the encrypted string:
Create or replace function testpwd (password in varchar2)
Return varchar2
Authid current_user
Is
--
Raw_key raw (128): = hextoraw ('0123456789abcdef ');
--
Raw_ip raw (1, 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
Dbms_obfuscation_toolkit.DESEncrypt (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 => 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
Unicode_str (upper (password), raw_ip );
Return crack (raw_ip );
End;
/