简体   繁体   English

通过存储过程,数据库中存储的密码与原始加密略有不同

[英]The stored password in the db slightly changed through storing process from the original encryption

I use Delphi 10.4 community edition and Firebird embedded database.我使用 Delphi 10.4 社区版和 Firebird 嵌入式数据库。

The problem: I usually store the login passwords in an 'user' table encrypted.问题:我通常将登录密码存储在加密的“用户”表中。 This is the algorithm I usually use (I know it is not the hardest to crack but this software only for myself so who bothers?)这是我通常使用的算法(我知道它不是最难破解的,但这个软件只适合我自己所以谁会烦恼?)

function Titkositas(Jelszo: string; Code: LongInt): string;
var
  Ciklus: Byte;
begin
  RandSeed := Code;
  Result := '';
  for Ciklus := 1 to Length(Jelszo) do
    Result := Result + Chr(Ord(Jelszo[Ciklus]) xor Random(256));
end;

Once it was encrypted I stored it in the table.加密后,我将其存储在表中。

procedure TFrmadmin2.BitBtn5Click(Sender: TObject);
var
  s, s2, m, t, dt, most: string;
begin
  s := '';
  s2 := '';
  m := '';
  t := '';    dt:='';  most:='';
  if trim(edit3.Text) = trim(edit4.Text) then
  begin

    if ((edit1.text <> '') and (edit2.text <> '') and (edit3.text <> '') and (edit4.text <> '')) then
    begin
      if (not TDM1.MenuTrans.InTransaction) then
        TDM1.MenuTrans.StartTransaction;
      try
        with insertuser do
        begin
          prepare;
          begin
            ParamByName('NEV').asString := trim(edit1.Text);
            ParamByName('LOGIN').asString := trim(edit2.Text);
            ParamByName('PASSWD').asString := Titkositas(trim(edit4.text), 123456); //this is it!!!
            listbox1.items.add(Titkositas(trim(edit4.text), 123456));
            ParamByName('JOG').AsInteger := strtoint(trim(edit5.Text));
            dt:=DateTimeToStr(now);

            ParamByname('DATUM').Asstring :=dt;
            execproc;
            if TDM1.MenuTrans.InTransaction then TDM1.MenuTrans.CommitRetaining;
....

So, it worked perfectly in the past, but now I noticed that the encryption does not function properly (or something else).所以,它在过去工作得很好,但现在我注意到加密功能不正常(或其他)。 I have not got a clue what the problem could be: So this should be the password after encryption: a÷~D 2¥我不知道问题可能是什么:所以这应该是加密后的密码: a÷~D 2¥
But it is stored in the table: a÷~D 2Y Can you see the slight difference?但是表中存储的是: a÷~D 2Y你能看出细微的差别吗? It means when I try to log in it does not work because the password I know was changed through the storing process.这意味着当我尝试登录时它不起作用,因为我知道的密码已通过存储过程更改。 I thought it could be because of the character set of the Firebird db I registered.我认为这可能是因为我注册的 Firebird 数据库的字符集。 I changed it to Unicode, ISO-1, default but nothing was changed.我将其更改为默认的 Unicode、ISO-1,但没有任何更改。

I double checked the above code so I printed out the encrypted password in a showmessage which showed proper result and then debugged it from row to row and when it was executed then it still showed the right encrypted characters but then when I checked in the table it was slightly different.我仔细检查了上面的代码,所以我在显示正确结果的 showmessage 中打印出加密密码,然后一行一行地调试它,当它被执行时它仍然显示正确的加密字符但是当我检查表时它略有不同。

Has anyone got an idea what the problem could be?有没有人知道问题可能是什么?

XOR-ed string is not a string anymore.异或字符串不再是字符串。 It is an array of bytes.它是一个字节数组。 You cannot handle it as a string, store as string, etc because for strings the range of valid codes is limited and strings transformations between charsets may be irreversible.您不能将其作为字符串处理、存储为字符串等,因为对于字符串而言,有效代码的范围是有限的,并且字符集之间的字符串转换可能是不可逆的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM