Login screen acting incoherent

Asked

Viewed 156 times

2

I set up a login screen where the user must enter login and password with the code below:

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 password login is as follows:

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

after filling in the fields the step is to confirm:

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

Login table:

inserir a descrição da imagem aqui At this point, the record goes into the database

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

Where am I going wrong?

  • has how to display the login table structure ?

  • added the question

  • error or simply not log ?

  • do not log, give the message I put of password or incorrect user

  • opens the database and takes a "print" and shows the data as it is in the database, if possible table details, field type etc, id, primary key!

  • edited the question

  • Ok, if the data is recorded correctly, we will change this here and see if something happens: Fmhome.ADOLogin.SQL.add('Select * from login Where usuario = :user AND password = :password'); Remove double quotes!

  • negative, other passwords do not work, the one with Id_login 1 works.

  • give a Truncate in this table and register 1 new user! Then register another different user

  • there’s something wrong, if I put anything in the login field and the correct password, it enters the system

  • Fmhome.ADOLogin.SQL.add('Select FIRST 1 * FROM login Where user = :user AND password = :password'), just tested here, this works too

  • remains the same...

Show 7 more comments

2 answers

2


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

Edited: On your table, put the new field login as a 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 the . Open:

Application.MessageBox(FMHome.ADOLogin.FieldByName('usuario').AsString,'Usuário Logado',MB_OK+MB_ICONINFORMATION);
  • An additional important in response!

0

in the following procedure:

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

check if your Adodslogin SQL is with or without Where, if you are with Where better remove the same leave only:

select * from Login

and I don’t know if it changes anything, but I always prefer to work with append in place of insert.

As a tip to try to solve the problem or someone to help you. When including and accessing the system with the new user see how the table of your database was, whether or not it included the record and is saved in the correct way.

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.