Autor Beitrag
F.Art
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 434



BeitragVerfasst: Do 17.06.04 23:28 
Ich möchte mit ServerSocket eine Passwort abfrage ein binden.
Jeder Client der sich ein loggen möchte muss das richtige PW senden sonst wird der jeweilige client nicht zugelassen.
Wie realisiere ich das?
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Do 17.06.04 23:37 
Hi!

Wie sieht denn dein Ansatz aus?

Cu,
Udontknow
F.Art Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 434



BeitragVerfasst: Fr 18.06.04 00:45 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.ServerClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
begin
Befehle := Socket.ReceiveText;

if 'Passwort='+Passwort='Passwort=' then else
   if 'Passwort=test'=Befehle then else
      if 'Passwort='+Passwort=Befehle then else Server.Socket.Connections[0].SendText('Passwort richtig'); 

if Befehle='Server aus' then begin
   Server_off:='aus';
   end;

...

Befehle := '';
end;


So funktioniert das zwar mit einer PW abfrage aber die anderen Befehle funken nicht mehr richtig.

Ich benutze OnClientRead um die Befehle ab arbeiten zu lassen.
Kann ich die PW abfrage nicht irgendwie in OnClientConnect einbauen?
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Di 22.06.04 11:46 
[quote="F.Art
So funktioniert das zwar mit einer PW abfrage aber die anderen Befehle funken nicht mehr richtig.[/quote]

Was heisst das? Debugge doch dort einfach mal, ein Breakpoint wirkt oft wahre Wunder.

Cu,
Udontknow
Stevie
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 85

Windows 7
Delphi XE Professional
BeitragVerfasst: Di 22.06.04 13:29 
Hallo mal wieder...

Ich hätte da einen Vorschlag. Das ganze basiert auf der Tatsache, dass jede ClientVerbindung über einen Pointer verfügt, der auf ein frei definierbares Objekt zeigen kann. Das mache ich mir zunutze, um ein eigenes Objekt zu benutzen, dass über Information verfügt, die den Client betreffen. Dort kann man dann z.B. einen Namen pflegen, der für das Finden der Verbindung über den Namen wichtig ist usw...

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:
type
  TClientInfo = class
    LoggedIn: Boolean;
  end;

...

procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  Socket.Data := Pointer(TClientInfo.Create);
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  if not TClientInfo(Socket.Data).FLoggedIn then
  begin
    if Socket.ReceiveText <> Passwort then
      Socket.Close
    else
      TClientInfo(Socket.Data).FLoggedIn := True;
  end
  else
    ...
end;

procedure TForm1.ClientSocket1Connect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  Socket.SendText('geheim');
end;
F.Art Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 434



BeitragVerfasst: Di 22.06.04 15:55 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
if not TClientInfo(Socket.Data).LoggedIn then begin
   if Socket.ReceiveText <> 'Passwort='+Passwort then else
      if Socket.ReceiveText <> 'Passwort=Admin' then else
         if Socket.ReceiveText <>'Passwort='+Passwort then else Socket.Close
   end else TClientInfo(Socket.Data).LoggedIn := True;


Wo ist hier noch der Fehler?
Stevie
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 85

Windows 7
Delphi XE Professional
BeitragVerfasst: Di 22.06.04 16:01 
F.Art hat folgendes geschrieben:
Wo ist hier noch der Fehler?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
if not TClientInfo(Socket.Data).LoggedIn then 
begin
  if Socket.ReceiveText = 'Passwort='+Passwort then 
    if Socket.ReceiveText = 'Passwort=Admin' then
      if Socket.ReceiveText = 'Passwort='+Passwort then
        Socket.Close;
end
else
  TClientInfo(Socket.Data).LoggedIn := True;


Ich hab's einfach nur mal umgeformt, du müsstest den Fehler jetzt selber finden!
F.Art Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 434



BeitragVerfasst: Mi 23.06.04 12:39 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
if Passwort = '' then else begin
   if not TClientInfo(Socket.Data).LoggedIn then begin
      if 'Passwort=Admin' = Socket.ReceiveText then else
         if 'Passwort='+Passwort = Socket.ReceiveText then else begin
            Server.Socket.Connections[0].SendText('Passwort falsch');
            Socket.Close
            end;
      TClientInfo(Socket.Data).LoggedIn := True;
      end;
   end;


Ich könnte noch mal Hilfe gebrauchen.
Irgendwie ist jedes gesendete PW falsch.
Wo liegt der Fehler?
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Mi 23.06.04 13:22 
Du hast einen Stil drauf, der ist einmalig. Was soll denn das "then else" immer?

Warum rufst du so oft Socket.ReceiveText auf? Jedes Mal, wenn du das aufrufst, wird versucht, erneut Daten vom Socket zu lesen. Beim ersten Mal hast du "passwort=Admin" als Returnvalue, beim nächsten Mal ''.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var Command:String;
begin
  //Kommando holen
  Command:=Socket.ReceiveText;

  //Passwort benötigt und noch nicht eingeloggt?
  if (Passwort <>''and (not TClientInfo(Socket.Data).LoggedIn) then 
  begin  
    if Command<>'Passwort='+Passwort then      
    begin
      Socket.SendText('Passwort falsch');  
      Socket.Close;  
    end
    else
      TClientInfo(Socket.Data).LoggedIn := True;  
  end;
end;


Cu,
Udontknow
F.Art Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 434



BeitragVerfasst: Mi 23.06.04 14:27 
Erstmal danke an Alle die mir geholfen haben.
Nun funzt es.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
if (Passwort <>''and (not TClientInfo(Socket.Data).LoggedIn) then begin
   if Befehle <> 'Passwort='+Passwort then
      if Befehle <> 'Passwort=Admin' then begin
         Socket.SendText('Passwort falsch');
         Socket.Close;
   end else TClientInfo(Socket.Data).LoggedIn := True;
   end;


Ich weis mein Stil ist eigen aber ich habe alles privat und nur durch selbst erlernen oder durch Beispiele erlernt. Habe nie programmieren gelernt.

KAnn mir noch Jemand folgendes erläutern '<>' was bedeutet dies genau?
FaTaLGuiLLoTiNe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 200
Erhaltene Danke: 5

Windows 7, Windows 8.1
Delphi XE
BeitragVerfasst: Mi 23.06.04 14:35 
Zitat:

Ich weis mein Stil ist eigen aber ich habe alles privat und nur durch selbst erlernen oder durch Beispiele erlernt. Habe nie programmieren gelernt.


Das geht hier glaub' ich einigen so ...

Zitat:

KAnn mir noch Jemand folgendes erläutern '<>' was bedeutet dies genau?


Das ist ein relationaler Operator und bedeutet "ungleich".

_________________
<< FaTaLGuiLLoTiNe >>
Rhinoceroses don't play games!
F.Art Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 434



BeitragVerfasst: Mi 23.06.04 14:45 
Warum wir <> stat = genommen müsste doch auch gehen.
FaTaLGuiLLoTiNe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 200
Erhaltene Danke: 5

Windows 7, Windows 8.1
Delphi XE
BeitragVerfasst: Mi 23.06.04 14:50 
Zitat:

Warum wir <> stat = genommen müsste doch auch gehen.


Nein, "<>" ist quasi das genaue Gegenstück zu "=".

Ich meine, im Grunde hast du schon recht, so wie du das gemacht hast (if ... then else ...) läuft das schon aufs Gleiche hinaus, ist aber viel weniger leserlich und von daher fehleranfälliger.

Sieht auch irgendwie strange aus.

_________________
<< FaTaLGuiLLoTiNe >>
Rhinoceroses don't play games!
F.Art Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 434



BeitragVerfasst: Mi 23.06.04 15:03 
OK nun verstehe ich den genauen Sinn.
F.Art Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 434



BeitragVerfasst: Mi 23.06.04 21:52 
Habe leider noch ein Bug den ich nicht weg bekomme.
Wenn das PW zb Test eingestellt wurde kann man sich mit test einloggen aber keine funktionen senden da er sich dann wieder ausloggt und Passwort falsch aus gibt.
Nehme ich das PW Admin da gibt es keine probleme.
Hat jemand ne Idee?

Ergänzung:
----------
Habe das Problem gelöst. Hier der Code für Leute die sich dafür interessieren.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
if (Passwort <>''and (not TClientInfo(Socket.Data).LoggedIn) then begin
   if (Befehle <> 'Passwort='+Passwort) and (Befehle <> 'Passwort=Admin'then begin
         Socket.SendText('Passwort falsch');
         Socket.Close;
   end else TClientInfo(Socket.Data).LoggedIn := True;
   end;