Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > Software > SHA1 hash

Reply
Thread Tools

SHA1 hash

 
 
MohammedNgum MohammedNgum is offline
Junior Member
Join Date: Jan 2008
Posts: 1
 
      01-29-2008
Hi,
I wrote a program in delphi to sha1 hash user id before sending the hash value for logon as only hash values are allowed for logon. My code works but produces an incorrect hash value. I know the hash is incorrect because i cannot logon with it and a website that gives hash values produces a different value which logs me on. I have copied the code below. Any 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 Digestig; 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[i] := Byte(id[i]);
showMessage(Char(Buffer[i]));
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[i]));
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[i]));
end;
DCP_sha11.Final(Digest);
showMessage('content of digest after final');
for i := 0 to length(Digest) do
begin
showMessage(char(Digest[i]));
end;

s:= '';
for i:= 0 to 19 do
s:= s + inttohex(Digest[i],2);
showMessage(s);
showMessage(inttostr(length(s)));
//logs on fine with correct hash value
//s:= '';
// s := '7a0df5cff2e39ad0ebea282f03d3d5498b51dc0d';
IdTCPClient3.IOHandler.write('LOGON,'+s+','+#13+#1 0);
str := IdTCPClient3.IOHandler.ReadLn(','+#13+#10,20);
showMessage(str);
IdTCPClient3.Disconnect;
end;

end.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Re: Digitally Signing a XML Document (using SHA1+RSA or SHA1+DSA) Adam Tauno Williams Python 2 12-30-2010 10:23 AM
SHA1 hash generator in hex Al Murphy Java 5 01-07-2009 04:33 PM
Form sha1.hexdigest to sha1.digest LMZ Python 5 04-06-2008 09:50 PM
SHA1 length of resulting hash Dil via .NET 247 ASP .Net 0 08-04-2004 12:53 PM



Advertisments