Jump to content

Still having problems with login form


sysjames

Recommended Posts

I am still having problems with my login form that I hope someone can help me with.  The relevant code in the login form follows.  The problem is that it will not present the error message at all, but just loops and finally exits without presenting an error message.  I hope someone can give me a clue as to why it is behaving this way.

Procedure TUniLoginForm1.LoginBtnClick(Sender: TObject);
Var
   Acct: TAccount;
Begin
Acct := TAccount.Create;
Try
   ModalResult := mrNone;
   While ModalResult = mrNone Do
      If LoadAccount(EmailEntry.Text, PassEntry.Text, Acct) Then
         Begin
         UniMainModule.SetAcct(Acct.SerialClass);
         ModalResult := mrOK
         End
      Else
         Begin
         MessageDlg('Password or Email is in error',mtWarning,[mbOK]); <<<<<<<Does not present this message dialog
         Inc(ErrorCount);
         If ErrorCount > 3 Then
            ModalResult := mrCancel;
         End;
Finally
   Acct.Free;
End;
End;
 

The LoadAccount that is called is:

Function LoadAccount(Const Email, Pass: String; Var acct: TAccount): Boolean;
Var
   MS: TMemoryStream;
Begin
MS := TMemoryStream.Create;
Result := True;
Try
   Try
      DoGetObject('acct.' + StringToHex(LowerCase(Email)), MS);
      acct.SerialClass := MS;
   Except
      Result := False;
   End;
   If (acct.Pass <> Pass) And (acct.AltPass <> Pass) Then
      Result := False;
Finally
   MS.Free;
End;
End;
 

Link to comment
Share on other sites

1 hour ago, sysjames said:

I am still having problems with my login form that I hope someone can help me with.  The relevant code in the login form follows.  The problem is that it will not present the error message at all, but just loops and finally exits without presenting an error message.  I hope someone can give me a clue as to why it is behaving this way.

Procedure TUniLoginForm1.LoginBtnClick(Sender: TObject);
Var
   Acct: TAccount;
Begin
Acct := TAccount.Create;
Try
   ModalResult := mrNone;
   While ModalResult = mrNone Do
      If LoadAccount(EmailEntry.Text, PassEntry.Text, Acct) Then
         Begin
         UniMainModule.SetAcct(Acct.SerialClass);
         ModalResult := mrOK
         End
      Else
         Begin
         MessageDlg('Password or Email is in error',mtWarning,[mbOK]); <<<<<<<Does not present this message dialog
         Inc(ErrorCount);
         If ErrorCount > 3 Then
            ModalResult := mrCancel;
         End;
Finally
   Acct.Free;
End;
End;
 

The LoadAccount that is called is:

Function LoadAccount(Const Email, Pass: String; Var acct: TAccount): Boolean;
Var
   MS: TMemoryStream;
Begin
MS := TMemoryStream.Create;
Result := True;
Try
   Try
      DoGetObject('acct.' + StringToHex(LowerCase(Email)), MS);
      acct.SerialClass := MS;
   Except
      Result := False;
   End;
   If (acct.Pass <> Pass) And (acct.AltPass <> Pass) Then
      Result := False;
Finally
   MS.Free;
End;
End;
 

void __fastcall TUniLoginForm1::UniBitBtn2Click(TObject *Sender)
{
//登录
UniMainModule()->loginUserNo=UniEdit1->Text;
//
UniQuery1->Close();
UniQuery1->SQL->Clear();
UniQuery1->SQL->Add("select * from user_info where user_no=:p1"); UniQuery1->ParamByName("p1")->Value=UniMainModule()->loginUserNo; UniQuery1->Open();
if(UniQuery1->RecordCount<1)
    {
    ShowMessage("该用户不存在,请先注册用户!");
    UniBitBtn1->Click();
    return;
    }
//
UniQuery1->Close();
UniQuery1->SQL->Clear();
UniQuery1->SQL->Add("select * from user_info where user_no=:p1 and user_pass=:p2"); UniQuery1->ParamByName("p1")->Value=UniMainModule()->loginUserNo; UniQuery1->ParamByName("p2")->Value=AESEncryptStrToHex(UniEdit2->Text.Trim(), UniMainModule()->aesKey, TEncoding::ANSI, TEncoding::UTF8,       kb128, UniMainModule()->aesKey, pmZeroPadding, false,rlCRLF, rlCRLF); UniQuery1->Open();
if(UniQuery1->RecordCount<1)
    {
    ShowMessage("密码错误!");
    UniEdit2->SetFocus();
    return;
    }
UniMainModule()->loginUserName=UniQuery1->FieldByName("user_name")->AsString;
UniMainModule()->loginUserTeam=UniQuery1->FieldByName("team_name")->AsString;
UniMainModule()->loginUserPart=UniQuery1->FieldByName("part_name")->AsString;
UniMainModule()->loginUserInst=UniQuery1->FieldByName("inst_name")->AsString;
UniMainModule()->loginUserTel1=UniQuery1->FieldByName("user_tel1")->AsString;
UniMainModule()->loginUserTel2=UniQuery1->FieldByName("user_tel2")->AsString;
UniMainModule()->loginUserStat=UniQuery1->FieldByName("user_stat")->AsString;
UniMainModule()->loginUserMail=UniQuery1->FieldByName("user_mail")->AsString;
UniMainModule()->loginUserHead=UniQuery1->FieldByName("user_head")->AsString;
//更新登录状态
UniQuery1->Close();
UniQuery1->SQL->Clear();
mySql="update user_info set user_stat='在线' where user_no=:p1";
UniQuery1->SQL->Add(mySql);
UniQuery1->ParamByName("p1")->Value=UniMainModule()->loginUserNo;
UniQuery1->ExecSQL();
//
ModalResult=mrOk;
//this->Close();
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...