I wrote a program to hash logon id as a hash value is required to logon. The problem am having is that the hash value am getting is wrong for some reason. (Confirmed the correct hash value on a sha1 hashing website. This logs me on fine). Please have a look at my code below. Any kind of help will be appreciated. Thanks in advance.
unit globallive;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, DCPcrypt2, DCPsha1, DCPripemd160;
type
Buf = Array[0..63] of byte;
Dig= array[0..19] of byte;
TForm1 = class(TForm)
IdTCPClient3: TIdTCPClient;
Button3: TButton;
DCP_sha11: TDCP_sha1;
DCP_ripemd1601: TDCP_ripemd160;
procedure Button3Click(Sender: TObject);
procedure IdTCPClient3Connected(Sender: TObject);
procedure SHA1Update(const Buffer: Buf; Size: longint; var Digest:Dig; username: String);
private
{ Private declarations }
public
Len : longword;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button3Click(Sender: TObject);
begin
IdTCPClient3.Connect('127.0.0.1',30257)
end;
//get user id then call hashing procedure
procedure TForm1.IdTCPClient3Connected(Sender: TObject);
var
i : integer;
Buffer : Buf;
Digest : Dig;
id : String;
int : Integer;
begin
showMessage('connected');
id := FormatDateTime('YYMMDDHHMM', now);
id := id + 'demofleet';
showMessage(id);
ZeroMemory(@Buffer, SizeOf(Buffer));
for i := 1 to Length(id) do
begin
Buffer := Byte(id);
showMessage(Char(Buffer));
end;
SHA1Update(Buffer,Length(Buffer),Digest,id);
end;
//perform hashing and use hash value to logon
procedure TForm1.SHA1Update(const Buffer:Buf; Size:longint; var Digest: Dig; username: String);
var
s : String;
i : integer;
str : String;
test : Boolean;
begin
DCP_sha11.Init;
showMessage('content of buffer before update');
for i := 1 to length(username) do
begin
showMessage(char(Buffer));
end;
DCP_sha11.Update(Buffer,sizeof(Buffer));
ZeroMemory(@Digest, SizeOf(Digest));
showMessage('content of digest before final');
for i := 0 to length(Digest) do
begin
showMessage(char(Digest));
end;
DCP_sha11.Final(Digest);
showMessage('content of digest after final');
for i := 0 to length(Digest) do
begin
showMessage(char(Digest));
end;
s:= '';
for i:= 0 to 19 do
s:= s + inttohex(Digest,2);
showMessage(s);
showMessage(inttostr(length(s)));
//logs on fine with correct hash value
//s:= '';
// s := '7a0df5cff2e39ad0ebea282f03d3d5498b51dc0d';
IdTCPClient3.IOHandler.write('LOGON,'+s+','+#13+#10);
str := IdTCPClient3.IOHandler.ReadLn(','+#13+#10,20);
showMessage(str);
IdTCPClient3.Disconnect;
end;
end.