Search code examples
delphidelphi-xe2firemonkeydelphi-xedelphi-xe7

Delphi Login Form using App Tethering by Connecting to SQLite Database


Hi, EveryBody!

I'm new to programming!

I need your help plz.

I've 2 project:

1. Project Login page. Using App Tethering and 2 buttons(Connect button =>connects to the server AND Login button=>Sends request to the Server to check Valid username and password).

2. Project Server page. In a Server Page using App tethering and FDQuery +(SQLite database test.db). When Client Connects to the Server and sends request to the Server to check valid username and password it gives wrong result. plz help me to make work correctly.

Client And Server

1 Project Code:

procedure TfAuth.bLogin(Sender: TObject);
begin
  tAProfile.SendString(tManager.RemoteProfiles.First,'Login',tLogin.Text);
  tAProfile.SendString(tManager.RemoteProfiles.First,'Password',tPassword.Text);
end;

2. Project Code: I creat global var

 private

    { Private declarations }
  public
    { Public declarations }
  end;

var

  aLogin, aPassword:string;

implementation


{$R *.fmx}

Then I put put this code on TetherAppProfile=>OnResourceReceived :

procedure TfServerPage.tAProfileResourceReceived(const Sender: TObject;
  const AResource: TRemoteResource);
  begin

   if AResource.Hint='Login' then
      begin
      aLogin:=AResource.Value.AsString;
      end;

   if AResource.Hint='Password' then
      begin
      aPassword:=AResource.Value.AsString;
      end;
 rQuery.Close;
      rQuery.SQL.Clear;
      rQuery.SQL.Add('select * from authoriation where name='+QuotedStr(aLogin)+'and password='+QuotedStr(aPassword));
      rQuery.Open;
      if rQuery.RecordCount=0 then   // No record found for user
        ShowMessage('Be sure user name and password is correct')
      else
        begin
          ShowMessage('Success!');
        end;

Solution

  • Modify your code as follows:

    In client

    procedure TfAuth.bLogin(Sender: TObject);
    var
      s: string;
    begin
      s := tLogin.Text + #13 + tPassword.Text;
      tAProfile.SendString(tManager.RemoteProfiles.First,'Login',s);
    //  tAProfile.SendString(tManager.RemoteProfiles.First,'Login',tLogin.Text);
    //  tAProfile.SendString(tManager.RemoteProfiles.First,'Password',tPassword.Text);
    end;
    

    Note!This uses the server resource named 'Login'.

    In server

    procedure TfServerPage.tAProfileResourceReceived(const Sender: TObject;
      const AResource: TRemoteResource);
    var
      s: string;
    begin
    // replace current code before rQuery.Close with the following
      s := AResource.Value.AsString;
    
      aLogin := copy(s, 1, Pos(#13, s)-1);
      aPassword := copy(s, Pos(#13, s)+1, Length(s));
    
      rQuery.Close;
    // continue with rQuery
    // ...
    end;
    

    Alternative in the server using SplitString()

    uses System.Types, System.StrUtils ...;
    
    procedure TFrmLoginServer.ServTetProfResourceReceived(const Sender: TObject;
      const AResource: TRemoteResource);
    var
      ss: TStringDynArray;
    begin
      ss := SplitString(AResource.Value.AsString, #13);
      aLogin := ss[0];
      aPassword := ss[1];
    end;