Autor Beitrag
Master-Basti
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73



BeitragVerfasst: Mo 19.12.05 15:49 
Hallo zusammen!

Habe eine Internetseite und ein Delphiprogramm.
Über das Delphiprogramm möchtge ich die Kunden mit einem Passwort eintragen, über die Internetseite kann das Passwort durch die Kunden allerdings auch geändert werden. Allerdings erzeugt die MD5 Funktion von php einen anderen HAsh als die von Delhi, sodass die User sich nicht einloggen können.

Hat jemand eine Idee, was ich da am besten machen kann ?

Gruß

MAster-Basti


Moderiert von user profile iconGausi: Topic aus Sonstiges verschoben am Do 22.12.2005 um 09:07
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mo 19.12.05 19:19 
ohne ein bisschen nähere erklärungen und Code von dir kann man nur Raten und dir nicht helfen !

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Mo 19.12.05 19:21 
Wenn beides MD5 ist, müsste auch bei beiden das gleiche rauskommen. Wird bei beiden das Passwort unmodifiziert durch die Hash-Funktion gejagt? Könnte es an unterschiedlichen Zeichensatz-Encoding liegen? Was kommt den raus, wenn du das Passwort mit einem MD5 Kommandozeilentool verschlüsselst?

Stefan

_________________
Ein Computer ohne Windows ist wie eine Schokoladentorte ohne Senf.
Master-Basti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73



BeitragVerfasst: Mo 19.12.05 21:11 
Danke erstmal für eure Antworten.

Mit Delphi füge ich das Passwort wie folgt ein:


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
function TForm22.RandomPassword():String;
var str:String;
PLen : Integer;
begin
Randomize;
PLen := 8;

//string with all possible chars
str:='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
Result:='';

  repeat
  Result:=Result+str[Random(Length(str))+1];
  until(Length(Result)=PLen)

end;

procedure TForm14.InsertKdExt(Kundendaten : Client; KundenID: Integer);
var
md5_digi : TMD5digest;
begin

md5_digi := MD5String(Form22.RandomPassword);
....
Fieldbyname('kennwort').AsString := MD5DigestToStr(md5_digi);
....


Nun, und über php nutze ich ganz normal die php-Funktion md5(string)

Hash-Wert für Passwort "zzcouIH0"
in Delphi: 49413E749F8E03F7C84A0302A7A45576
in php über md5: ae1fd4e7f8d44cd02c5be2ec44936e66

Noch eine Idee ? ;-)

Gruß

Master-Basti

Ps: VOn hier ist übrigens die Unit md5

{******************************************************************}
{ MD5 Hashsum Evaluation Unit For Borland Delphi }
{ }
{ Copyright © 2002 by Dimka Maslov }
{ E-mail: mail@endimus.com, }
{ Web-site: www.endimus.com }
{ }
{ Derived from the RSA Data Security, Inc. }
{ MD5 Message-Digest Algorithm described in RFC 1321 }
{ www.faqs.org/rfcs/rfc1321.html }
{******************************************************************}
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Mo 19.12.05 21:38 
Irgendwo hab ich mal diesen Code her, der funktioniert einwandfrei und bringt anscheinend auch dasselbe Ergebnis, wie die PHP-Funktion:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
function gethashstr(pwd: String): String;
var hash:T4x4LongWordRecord;
    hashstr,S1:String;
    i:integer;
begin
     SetLength(hashstr,16);
     with TIdHashMessageDigest5.Create do begin
          hash:=HashValue(pwd);
          Move(hash,hashstr[1],16);
          for i := 1 to Length(hashstr) do
              S1 := S1 + Format('%02x', [Byte(hashstr[i])]);
          while Pos(' ', S1) > 0 do S1[Pos(' ', S1)] := '0';
          hashstr:=S1;
          result:=hashstr;
          Free;
          end;
end;

Du brauchst dafür allerdings die Indy-Files IdHash und IdHashMessageDigest
Master-Basti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73



BeitragVerfasst: Di 20.12.05 11:41 
Funktioniert leider auch nicht.
Kommt wieder ein unterschiedlicher Hash raus.... :(

Kann doch egtl. nicht sein oder ?
Ich mein, ist md5 nich gleich md5 ?

Bitte dringend um Hilfe, sonst kann ich das Programm vergessen.

Gruß

MAsterBasti
Der Jan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

Win2k prof, WinXP prof, Linux
D6 Prof, BCB4 Std, BCB6 Ent, BDS 2006 Ent
BeitragVerfasst: Di 20.12.05 12:35 
Mit dieser MD5 Funktion (siehe Anhang) hab ichs getestet, kommt der selbe Hash raus (AE1FD4E7F8D44CD02C5BE2EC44936E66)
Einloggen, um Attachments anzusehen!
_________________
Gruß, Jan
Master-Basti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73



BeitragVerfasst: Di 20.12.05 13:02 
Hi Jan,

wie hast du den String umgewandelt ?

Ich hab es gerade mit

ausblenden Delphi-Quelltext
1:
Fieldbyname('kennwort').AsString := md5print(md5string(Form22.RandomPassword));					


versucht, mit dem Ergebnis, dass ich wieder einen anderen Hash habe.....
Muss ich vielleicht sonst noch irgendetwas beachten ? Feldtyp in der SQL Datenbank, etc ?

Gruß

Master-Basti
stifflersmom
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 194

XP /XP PRO/ SuSE div.
D1 - D7, BDS 2006
BeitragVerfasst: Di 20.12.05 14:32 
Dein Feldtyp sollte schon ein Textfeld sein, damit keine Umwandlung mehr vorgenommen wird.
Der Jan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

Win2k prof, WinXP prof, Linux
D6 Prof, BCB4 Std, BCB6 Ent, BDS 2006 Ent
BeitragVerfasst: Di 20.12.05 14:42 
Der Aufruf der MD5 Funktionen ist jedenfalls richtig. Check doch mal den Rückgabewert, bevor du ihn in die DB schreibst.

_________________
Gruß, Jan
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 20.12.05 15:03 
den string vorher mal in pchar umgewandelt ?
Master-Basti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73



BeitragVerfasst: Di 20.12.05 15:14 
@ stifflersmom:
Feldtyp ist varchar

@ Der Jan:
Wie hast du es denn genau gemacht ?

@ F34r0fTh3D4rk:
pchar(password) bringt leider auch nichts! Kommt dasselbe heraus!
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 20.12.05 15:34 
user profile iconMaster-Basti hat folgendes geschrieben:
@ stifflersmom:
Feldtyp ist varchar

@ Der Jan:
Wie hast du es denn genau gemacht ?

@ F34r0fTh3D4rk:
pchar(password) bringt leider auch nichts! Kommt dasselbe heraus!

ich meine du kannst dir ja nen md5 algo suchen, der mit pchar arbeitet, vielleicht kommt da das gleiche raus (wohl aber eher doch net)
Master-Basti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73



BeitragVerfasst: Di 20.12.05 15:37 
Jan hat es ja scheinbar geschafft, ist nur die Frage wie....
Der Jan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

Win2k prof, WinXP prof, Linux
D6 Prof, BCB4 Std, BCB6 Ent, BDS 2006 Ent
BeitragVerfasst: Di 20.12.05 15:58 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TfrmMain.edtStringChange(Sender: TObject);
begin
    edtHash.Text := UpperCase(MD5Print(MD5String(edtString.Text)));
end;


wobei edtString und edtHash Editfelder sind...
Einloggen, um Attachments anzusehen!
_________________
Gruß, Jan
Der Jan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

Win2k prof, WinXP prof, Linux
D6 Prof, BCB4 Std, BCB6 Ent, BDS 2006 Ent
BeitragVerfasst: Di 20.12.05 16:01 
user profile iconMaster-Basti hat folgendes geschrieben:

Feldtyp ist varchar


Tut zwar nix direkt zur Sache, aber nimm "char". Das Feld hat ne feste Länge, da brauchts kein "varchar"

_________________
Gruß, Jan
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Di 20.12.05 18:45 
user profile iconDer Jan hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TfrmMain.edtStringChange(Sender: TObject);
begin
    edtHash.Text := UpperCase(MD5Print(MD5String(edtString.Text)));
end;


wobei edtString und edtHash Editfelder sind...

:autsch: Ich hab mich schon gefragt, warum bei meiner was anderes rauskommen soll ... eine Sichtprüfung wäre vielleicht mal angebracht gewesen.
DeadlyAppearance
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 113

Win 7
Delphi 2010 Arch., C# VS 2008
BeitragVerfasst: So 25.12.05 15:09 
Hatte damals das gleiche Problem. Wobei ich nicht nur eine Einseitige verschlüsselung gebraucht habe, sondern in Delphi via Blowfish verschlüsseln und in PHP entschlüsseln.
Unter PHP ist das einzigware was Ver-/Entschlüsseln angeht Mcrypt. In Delphi habe ich nach langem Delphi Cryptography Package gefunden. Nun hat man auf Delphi sowie PHPbasis alles möglichen Verschlüsselungsarten die gleich arbeiten.

www.cityinthesky.co.uk/cryptography.html

_________________
Als du auf die Welt kamst, weintest du, und um dich herum freuten sich alle. Lebe so, daß, wenn du die Welt verläßt, alle weinen und du allein lächelst.
DIGIMan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Fr 16.11.07 17:43 
Ich habe das gleiche Problem und möchte das Meine Delphi Software sich in unsere Datenbank einloggt!
Alle Passwörter sind mit PHP md5 verschlüsselt.

Hier mein Versuch

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
unit DM_Main;

interface

uses
  SysUtils, Classes, DB, ZAbstractRODataset, ZAbstractDataset, ZDataset,
  ZConnection, IniFiles, MD5;

type
  TdmMain = class(TDataModule)
    ZConnection1: TZConnection;
    ZQuery_read: TZQuery;
    ZQuery_save: TZQuery;
    procedure DataModuleCreate(Sender: TObject);
    procedure DataModuleDestroy(Sender: TObject);
  private
    { Private-Deklarationen }
    FDatensatzID: string;
    FLoginIni: TCustomIniFile;
    FStartDir: string;
    FUserID: Integer;
  public
    function Login(const AUsername, APassword: string): Boolean;
    procedure Logout;
    procedure StoreLoginData(DoKeepData: boolean; const AUsername, APassword:
        string);
    { Public-Deklarationen }
    property DatensatzID: string read FDatensatzID write FDatensatzID;
    property LoginIni: TCustomIniFile read FLoginIni;
    property StartDir: string read FStartDir;
    property UserID: Integer read FUserID;
  end;

var
  dmMain: TdmMain;

implementation

{$R *.dfm}

var
  LoginDataName : string  = 'CamSoft.log';

procedure TdmMain.DataModuleCreate(Sender: TObject);
begin
  FStartDir := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)));
  FLoginIni := TMemIniFile.Create(FStartDir + '\' + LoginDataName);
end;

procedure TdmMain.DataModuleDestroy(Sender: TObject);
begin
  FreeAndNil(FLoginIni);
end;

function TdmMain.MD5(Str: String): String;
var  
  s: string;  
  i: integer;  
begin  
  result := '';
  IdCoderMD51.Reset;  
  IdCoderMD51.AutoCompleteInput := True;  
  s := IdCoderMD51.CodeString(Str);  
  for i := 1 to Length(s) do  
  begin  
    result := result + LowerCase(IntToHex(BYTE(s[i]), 1));
  end;  
end;  

function TdmMain.Login(const AUsername, APassword: string): Boolean;
begin
  Result := False;
  hash := MD5(APassword);
  ZQuery_read.Active := False;
  ZQuery_read.SQL.Text := 'Select id,username,passwort from users ' +
                          'WHERE username = "' + AUsername + '" AND passwort = "' + APassword + '"';
  ZQuery_read.Active := True;

  if not ZQuery_read.EOF then
  begin
    FUserID := ZQuery_read.FieldByName('id').AsInteger;
    //ZQuery_save.SQL.Text := 'Insert Into stats Set ' +
    //                        'UserID = :USERID, ' +
    //                        'Login  = :LoginTime, ' +
    //                        'Start_Time = :StartTime ';

    //ZQuery_save.ParamByName('UserID').AsInteger   := FUserID;
    //ZQuery_save.ParamByName('LoginTime').AsString := DateTimeToStr(Now);  // oder gleich direkt TimeToStr(Time);
    //ZQuery_save.ParamByName('StartTime').AsFloat  := Now;  // oder gleich direkt TimeToStr(Time);
    //ZQuery_save.ExecSQL;

    { Den neu erstellten Datensatz finden und die Kontakt_ID bestimmen }
    ZQuery_save.SQL.Text := 'Select LAST_INSERT_ID()';
    ZQuery_save.Active   := True;
    FDatensatzID         := ZQuery_save.Fields[0].AsString;
    // success
    Result := True;
  end
end;

procedure TdmMain.Logout;
begin
    ZQuery_save.SQL.Text := 'Update stats ' +
                            'Set logout = :Logout, ' +
                            'End_Time   = :EndTime ' +
                            'Where ID = :DatensatzID ';

    ZQuery_save.ParamByName('Logout').AsString      := DateTimeToStr(Now);
    ZQuery_save.ParamByName('EndTime').AsFloat      := Now;
    ZQuery_save.ParamByName('DatensatzId').AsString := FDatensatzID;
    ZQuery_save.ExecSQL;
end;

procedure TdmMain.StoreLoginData(DoKeepData: boolean; const AUsername,
    APassword: string);
begin
  if DoKeepData then
  begin
    FLoginIni.WriteInteger('Global''KeepData'1);
    FLoginIni.WriteString('Global''Name', AUsername);
    FLoginIni.WriteString('Global''PW', APassword);
  end
  else
  begin
    FLoginIni.WriteInteger('Global''KeepData'0);
    FLoginIni.WriteString('Global''Name''');
    FLoginIni.WriteString('Global''PW''');
  end;
  FLoginIni.UpdateFile;
end;

end.


Benutze die md5.pass und bekomme folgende Fehler! siehe Anhang!

Wie muß ich denn das machen das ich das APasswort in md5 verschlüsselt bekomme?
Vielen Dank

Moderiert von user profile iconmatze: Code- durch Delphi-Tags ersetzt
Einloggen, um Attachments anzusehen!
Blawen
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 616
Erhaltene Danke: 33

Win XP, Vista, 7
Delphi 5 Prof., BDS 2006 Prof. RAD Studio XE
BeitragVerfasst: Fr 07.12.07 11:09 
Welche "MD5.pas" Du verwendest, weiss ich nicht. Daher nur mal die gröbsten Schnitzer...


Diese Function deklarierst Du nicht:
ausblenden Delphi-Quelltext
1:
function TdmMain.MD5(Str: String): String;					


Wo deklarierst Du die Variable "Hash" ??
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
function TdmMain.Login(const AUsername, APassword: string): Boolean;
begin
  Result := False;
  hash := MD5(APassword);
  ....


Nur so nebenbei:
MD5 "verschlüsselt" Dein Passwort nicht, sondern erstellt einen Hash des Passworts.
Unterschied: Aus dem Hash kannst Du das Passwort nicht rekonstruieren - im Prinzip ist es nur ein Fingerabdruck zum vergleichen.

Ich arbeite mit einer anderen MD5.pas, da genügt folgender Aufruf:
ausblenden Delphi-Quelltext
1:
2:
sPasswort   := PW_Schutz.PW_Hash(MD5String(Edit2.Text));   // MD-5 Hashwert generieren
IF ZQ_Login.FieldByName('PASSWORT').AsString = sPasswort // Mit gesetztem PW vergleichen

Auf der Webseite von Fichtner.net finde ich sie nicht mehr, aber z.B. hier ist sie zu finden files.codes-sources....5Cmd5_test%5Cmd5.pas

_________________
Es kompilert, wir können ausliefern.
Und es kompiliert wieder - das Update ist fertig - bitte 100 Euro ;-)