Login screen acting incoherent

2

I installed a login screen where the user must enter login and password with the following code:

procedure TFMLogin.Img_confClick(Sender: TObject);
var verif: boolean;
begin
 FMHome.ADOLogin.SQL.add('Select * from "login" where "usuario" = :usuario AND "senha" = :senha');
  FMHome.ADOLogin.Parameters.ParamByName('usuario').Value := edt_usuario.Text;
  FMHome.ADOLogin.Parameters.ParamByName('senha').Value := edt_senha.Text;
  FMHome.ADOLogin.Open;
  try
    if Not (FMHome.ADOLogin.isEmpty) then
    begin
      Modalresult := mrok;
      verif := true;
    end
    else
    begin
      Application.MessageBox('Senha ou usuário incorretos!','Atenção',MB_OK+MB_ICONINFORMATION);
      edt_usuario.Clear;
      edt_senha.Clear;
      edt_usuario.SetFocus;
      verif := False;
    end;
  finally
    FMHome.ADOLogin.Close;

  end;
    if (verif = true) then
  begin
      FreeAndNil(FmLogin); //Libera o form de Login da memória
      Application.CreateForm(TFmHome, FmHome); //Cria a janela main
      Application.Run; //Roda a aplicação
  end;
end;

To create a new user if the person does not have the login password is as follows:

procedure TFMLogin.lbl_cadastroClick(Sender: TObject);
begin
UDM.ADODSLogin.open;
UDM.ADODSLogin.Insert;
FMCad_Login.showmodal;
end;

After completing the fields the step is to confirm:

procedure TFMCad_Login.Img_confClick(Sender: TObject);
begin
UDM.ADODSLogin.Post;
end;

Login table:

At this point, the registry goes to the database

But I have 3 registered users, and I can only enter the last one that was inserted and after a while I can only access with ID # 1

Where am I going wrong?

    
asked by anonymous 27.11.2015 / 19:05

2 answers

2

Hello, Add in your Table a new field login and instead of using usuario as Login we will use login as Login, now register 3 new users:

Edited: In your table, put the new login field as the primary key!

------------------------------------
usuario         - login   - senha
------------------------------------
joao santos     - jsantos - j48f2
marcos pereira  - marpere - mgn30ds
maria aparecida - mariaap - nm4n9dn
------------------------------------

Let's change:

FMHome.ADOLogin.SQL.add('Select * from login where usuario = :usuario AND senha = :senha');

To

FMHome.ADOLogin.SQL.add('Select usuario from login where usuario = :usuario AND senha = :senha');

Now after .Open:

Application.MessageBox(FMHome.ADOLogin.FieldByName('usuario').AsString,'Usuário Logado',MB_OK+MB_ICONINFORMATION);
    
28.11.2015 / 13:13
0

in the following procedure:

procedure TFMLogin.lbl_cadastroClick(Sender: TObject);
begin
   UDM.ADODSLogin.open;
   UDM.ADODSLogin.Insert;
   FMCad_Login.showmodal;
end;

Make sure your ADODSLogin's SQL is with or without the where, if it is with the best where to remove it, just leave it:

select * from Login

I do not know if something changes, but I always prefer to work with append instead of insert .

As a tip to try to solve the problem or someone can help you. When adding and accessing the system with the new user, see how your database table was, whether or not it included the registry and whether it is saved correctly.

I hope I have helped.

    
30.12.2015 / 15:45