1 Attachment(s)
Delphi, MySQL and Login!!!
Hi! I would like to making a login form for my Delphi application which basically get information such as login and password from web-site MySQL database. Obviously, the web-site is mine.
There are many users. If there is no such user in the database, then the application must say that there is no such user or this user is not registered. I would like to do it with some dialog screen which can be closed later.
Waiting for your suggestions.
Re: Delphi, MySQL and Login!!!
You can start by creating the main form of the application by creating a new Delphi project containing one form. This form is, by design, the main form.
If you change the name of the form to "TMainForm" and save the unit as "main.pas", the project's source code looks like (the project was saved as "PasswordApp"):
Code:
program PasswordApp;
uses
Forms,
main in 'main.pas' {MainForm};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TMainForm, MainForm) ;
Application.Run;
end.
More information here.
Re: Delphi, MySQL and Login!!!
You didn't get me. I need that the logins and passwords were taken from my web-site's SQL. Because, there will be many users. I don't think that it will work in such case.
Re: Delphi, MySQL and Login!!!
I am also trying to make a program for which i need a login screen, the first form has two edit boxes and two buttons with the cancel button that closes the program and the login button that checks username and password if it is correct or not. However, I keep getting an error for the code that i have written for the login button every time i click on it. I hope some one can help me by correcting the below code:
Code:
begin
If edit1.Text='Admin' Then
Begin
Edit1.Readonly:=true;
end
else
If edit2.Text='1234' Then
Begin
form2.Visible:=True;
end
else
Begin
ShowMessage('Incorrect username and password');
end;
Re: Delphi, MySQL and Login!!!
I don't see any code that belongs to SQL.
Re: Delphi, MySQL and Login!!!
Re: Delphi, MySQL and Login!!!
I happened to use Delphi language when I was in college for my thesis. Much better to HTML Code and much simpler. Try this one for your Deplhi Code : http://delphi.about.com/od/fullcodep...i_Projects.htm and http://www.firmmonster.com
Re: Delphi, MySQL and Login!!!
The following code goes into your project file :
Application.Initialize;
Application.Title := 'XYZ';
frmLogin := TfrmLogin.Create(Application);
frmLogin.ShowModal;
Application.CreateForm(TMainForm, mainForm);
Application.Run;
The following code goes into the OnClick() event of your login screen for the Login button. You need to set the database/connection properties for the query :
function TfrmLogin.ValidateLogin: Boolean;
var
bValidated : Boolean;
begin
try
bValidated := False;
try
qryLogin.SQL.Clear;
qryLogin.SQL.Add('Select user_login');
qryLogin.SQL.Add(' , User_Password');
qryLogin.SQL.Add(' from user');
qryLogin.SQL.Add(' where user_login = Upper(:UserLogin)');
qryLogin.SQL.Add(' and User_Password = Password(:UserPassword)');
qryLogin.SQL.Add(' and User_IsActive = ''Y''');
qryLogin.SQL.Add(' and User_LoginExpDate > Sysdate()');
qryLogin.Parameters[0].Value := UpperCase(Trim(edtLoginName.Text));
qryLogin.Parameters[1].Value := Trim(edtPassword.Text);
qryLogin.Open;
if qryLogin.RecordCount > 0 then begin
bValidated := True;
showmessage('Valid Login');
end;
except
on E : Exception do begin
ShowMessage('Exception in TfrmLogin.ValidateLogin: ' + E.message);
end;
end;
finally
result := bValidated;
end;
end;
In the above query, I have used the 'Password' function to encrypt the password. You may remove it if you don't want to encrypt the password.
Hope that helps you.
Re: Delphi, MySQL and Login!!!
Thanks, I will try it tomorrow.