口令加密问题

lyshrine 2004-01-02 12:11:56
我现在是这样实现的
数据库口令存在数据库中,用一个公用的低权限用户可以获取。修改权限为高权用户。
比如我在数据库中建了一个表DBKL里面存有数据库的密码(需要加密存放)
用一个公用的低权限用户(在注册表中可以获得)只可以有查询DBKL表的权限。这样得到数据库的口令,然后才可以连接。
但如果用户在ORACLE自带的工具中改了口令,则不能及时反馈到DBKL表中,且要是加密(在取口令的时候要解密)怎么实现?(怎么能及时更新?加密的算法?是不是要单独做个加密的程序,把改完的数据库口令加密后存到DBKL表中?)
如下
Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_LOCAL_MACHINE;
Reg.OpenKey('SOFTWARE\rcj',true);
if reg.ReadString('DBconnectstring')='' then
begin
reg.WriteString('DBconnectstring','pass');
reg.WriteString('DBusername','rcj');
end;
if reg.ReadString('systemuser')='' then
begin
reg.WriteString('systemuser','RCJ');
reg.WriteString('systemusergh','0004');
end;
try
f_database.Session.Connected:=false;
f_database.Session.LogonDatabase:=Reg.ReadString('DBconnectstring');
f_database.Session.LogonUsername:=Reg.ReadString('DBCXusername');
f_database.Session.LogonPassword:=Reg.ReadString('DBCXpassword');
f_database.Session.Connected:=true;
except
MessageDlg('查询口令失败,请与管理员联系',mtinformation,[mbok],0);
Application.Terminate;
end;
with ODS_log do
begin
close;
sql.Clear;
sql.Add('select dbkl from RCJ.DBKLB');
open;
dbkl:=fieldbyname('dbkl').asstring;
close;
end;
try
f_database.Session.Connected:=false;
f_database.Session.LogonDatabase:=Reg.ReadString('DBconnectstring');
f_database.Session.LogonUsername:=Reg.ReadString('DBusername');
f_database.Session.LogonPassword:=dbkl;
f_database.Session.Connected:=true;
for i:=0 to f_database.ComponentCount-1 do
begin
if f_database.Components[i].ClassName='TOracleDataSet' then
TOracleDataset(f_database.Components[i]).open;
end;
except
MessageDlg('数据库连接失败,请与管理员联系',mtinformation,[mbok],0);
Application.Terminate;
end;
...全文
111 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hlp912 2004-01-02
  • 打赏
  • 举报
回复
下面是加密的算法
String Ls_Addpass , Ls_Delpass ,Ls_Return //加密值和解密值
Integer Li_Key , Li_Count ,Li_Lenpass ,Li_Lenkey ,LI_repeat //密碼的長度,參數的長長

Li_Lenpass = Len(As_Password)
Li_Lenkey = Len(As_Key)
For Li_Count = 1 To Li_Lenpass

li_repeat = mod(li_count,li_lenkey)

if li_repeat = 0 then li_repeat = li_lenkey

Li_Key = Asc(Mid(As_Password,Li_Count,1)) &
- Asc(Mid(As_Key,li_repeat,1))

if li_key < 0 then li_key += 255

Ls_Return = ls_return + char(li_key)

Next

return ls_return


下面是解密的函數

String Ls_Addpass , Ls_Delpass ,Ls_Return //加密值和解密值
Integer Li_Key , Li_Count ,Li_Lenpass ,Li_Lenkey ,LI_repeat //密碼的長度,參數的長長

Li_Lenpass = Len(As_Password)
Li_Lenkey = Len(As_Key)
For Li_Count = 1 To Li_Lenpass

li_repeat = mod(li_count,li_lenkey)

if li_repeat = 0 then li_repeat = li_lenkey

Li_Key = Asc(Mid(As_Password,Li_Count,1)) &
+ Asc(Mid(As_Key,li_repeat,1))

if li_key > 255 then li_key -= 255

Ls_Return = ls_return + char(li_key)

Next

return ls_return
nhdj 2004-01-02
  • 打赏
  • 举报
回复
我现在想睡觉,顶一下

2,498

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧