我正在使用这个函数HASH_PASSWORD
当我在 MAXAPEX 云上执行此函数时,我无法执行此函数,因为他们使用 21c 数据库,并且此函数不再支持如何更改函数并使用 DBMS_CRYPTO 而不是 DBMS_OBFUSCATION_TOOLKIT ?
create or replace FUNCTION HASH_PASSWORD
(p_user_name in varchar2,
p_password in varchar2)
return varchar2
is
l_password varchar2(255);
-- The following salt is an example.
-- Should probably be changed to another random string.
l_salt varchar2(255) := '2345USFGOJN2T3HW89EFGOBN23R5SDFGAKL';
L_ENCRP_PASSWORD VARCHAR2(8);
L_PASS_LENGTH NUMBER(1);
L_PASS_ASCII NUMBER(8);
begin
--
-- The following encryptes the password using a salt string and the
-- DBMS_OBFUSCATION_TOOLKIT.
-- This is a one-way encryption using MD5
--
l_password := utl_raw.cast_to_raw (
dbms_obfuscation_toolkit.md5(
input_string => p_password ||
substr(l_salt,4,14) ||
p_user_name ||
substr(l_salt,5,10)));
/*
L_PASS_LENGTH := LENGTH(P_PASSWORD);
FOR I IN 1..L_PASS_LENGTH LOOP
L_PASS_ASCII := L_PASS_ASCII + (ASCII(SUBSTR(P_PASSWORD,I,1)) * I );
END LOOP;
l_password := L_PASS_ASCII + 15;
*/
return l_password;
end hash_password;
-- AUTHENTICATE USER Function;
/
您可以使用 STANDARD_HASH 或 DBMS_CRYPTO,两者根据以下测试过程给出相同的结果
- Should probably be changed to another random string.
declare
l_salt varchar2(255) := '2345USFGOJN2T3HW89EFGOBN23R5SDFGAKL';
L_ENCRP_PASSWORD VARCHAR2(8);
L_PASS_LENGTH NUMBER(1);
L_PASS_ASCII NUMBER(8);
l_password varchar2(255);
begin
--
-- The following encryptes the password using a salt string and the
-- DBMS_OBFUSCATION_TOOLKIT.
-- This is a one-way encryption using MD5
--
l_password := utl_raw.cast_to_raw(
dbms_obfuscation_toolkit.md5(
input_string => 'SAN' ||
substr(l_salt,
4,
14) ||
'BADSHA' ||
substr(l_salt,
5,
10)));
dbms_output.put_line(l_password);
select rawtohex(DBMS_CRYPTO.Hash(UTL_I18N.STRING_TO_RAW('SAN' ||
substr(l_salt,
4,
14) ||
'BADSHA' ||
substr(l_salt,
5,
10),
'AL32UTF8'),
2))
into l_password
from dual;
dbms_output.put_line(l_password);
select standard_hash('SAN' ||
substr(l_salt, 4, 14) ||
'BADSHA' ||
substr(l_salt, 5, 10),
'MD5')
into l_password
from dual;
dbms_output.put_line(l_password);
end;
我创建了新函数及其工作原理
create or replace function HIS_HASH_PASSWORD
(P_USERNAME in varchar2,
P_PASSWORD in varchar2)
return varchar2 is
l_password varchar2(4000);
l_hash_function number;
begin
l_hash_function := dbms_crypto.hash_sh1;
l_password := dbms_crypto.hash(utl_raw.cast_to_raw(P_USERNAME||P_PASSWORD),l_hash_function);
return l_password;
end;
/