表里有两个字段,如何用md5加密呢!
表里有两个字段是用户名和密码.有很多人都可以登到库里去,现在想用md5加密要使用什么方法加密呢!
------解决方案--------------------也可以在oracle 中使用存储过程进行加密
--3.2.1 创建数据表
--Drop Table Test_User;
CREATE TABLE Test_User (
UserName VARCHAR2(30) NOT NULL,
Password VARCHAR2(2000) NOT NULL
)
/
--3.2.2 创建程序包
Create Or Replace Package Test_MD5 AS
Function FN_GetMD5(P_Str In VarChar2)
Return VarChar2;
Function FN_CheckUser
(P_UserName In VarChar2
,P_Password In VarChar2)
Return Number;
End;
/
CREATE OR REPLACE PACKAGE BODY Test_MD5 AS
FUNCTION FN_GetMD5 (P_Str IN VARCHAR2)
RETURN VARCHAR2 AS
BEGIN
RETURN DBMS_OBFUSCATION_TOOLKIT.MD5(
input_string => Upper(P_Str));
END;
Function FN_CheckUser
(P_UserName IN VARCHAR2
,P_Password IN VARCHAR2)
Return Number
Is
L_Password VarChar2(2000);
BEGIN
SELECT
Utl_Raw.Cast_To_Raw(Password)
INTO
L_Password
FROM
Test_User
WHERE
Upper(UserName) = UPPER(P_UserName);
If Utl_Raw.Cast_To_Raw(FN_GetMD5(P_Password))=L_Password Then
Return 1;
Else
Return 0;
End If;
EXCEPTION
WHEN NO_DATA_FOUND THEN
Return 0;
END;
End;
/
--3.3 测试
Delete Test_User;
Insert Into Test_User Values( 'A ',Test_MD5.FN_GetMD5( 'aa '));
Insert Into Test_User Values( 'B ',Test_MD5.FN_GetMD5( 'bb '));
Commit;
Select Test_MD5.FN_CheckUser( 'a ', 'aa ') From Dual;
Select Test_MD5.FN_CheckUser( 'a ', 'bb ') From Dual;