For Newbie

Friday, 18 November 2011

Create a multi user login on Delphi 7


In building an application we are often confronted with cases where the user application consists of several circles or levels of data access. eg, for academic information systems for example, the system is later used by the school principal, teachers, students,. and of course, each job title has different data access, for example, teachers input grades, while students see the value of her on some subjects.
to deal with this case, the diperukan a system that has a multi-user login. so that it can be distinguished, as the admin user, students, teachers or others. The following is one example of a simple solution multi-user login.
with the specifications of the database using MS Access 2003, the second user is a guest and admin, and made use delpi7.
source for the login:





unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
ComboBox1: TComboBox;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
with adoquery1 do
begin
if combobox1.Text=’Admin’ then
begin
SQL.Clear;
sql.Add(‘select * from admin where username=”‘+edit1.Text+’”‘);
open;
if adoquery1.RecordCount <> 0 then
begin
if adoquery1.FieldByName(‘passwd’).AsString = edit2.Text then
begin
Application.MessageBox(‘Anda berhasil login sebagai administrator.’,'Selamat Datang’);
end
else
begin
Application.MessageBox(‘Maaf, Password yang anda masukkan salah.’,'Perhatian!’);
end;
end
else
begin
Application.MessageBox(‘Username anda tidak ditemukan.’,'Perhatian!’);
end;
end;
if combobox1.Text=’Guest’ then
begin
SQL.Clear;
sql.Add(‘select * from guest where username=”‘+edit1.Text+’”‘);
open;
if adoquery1.RecordCount <> 0 then
begin
if adoquery1.FieldByName(‘passwd’).AsString = edit2.Text then
begin
Application.MessageBox(‘Anda berhasil login sebagai guest.’,'Selamat Datang’);
end
else
begin
Application.MessageBox(‘Maaf, Password yang anda masukkan salah.’,'Perhatian!’);
end;
end
else
begin
Application.MessageBox(‘Username anda tidak ditemukan.’,'Perhatian!’);
end;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
application.Terminate;
end;
end.
————————————————-end———————————-
silakan download source lengkapnya di

Share on Facebook
Share on Twitter
Share on Google+

Related : Create a multi user login on Delphi 7