I just made an example in firebird.
too late.....
program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, SysUtils, CustApp
{ you can add units after this }
,ibconnection, db, sqldb;
type
{ TestFirebirdConsoleUsernameFirebird }
TestFirebirdConsoleUsernameFirebird = class(TCustomApplication)
protected
procedure DoRun; override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure WriteHelp; virtual;
end;
{ TestFirebirdConsoleUsernameFirebird }
procedure TestFirebirdConsoleUsernameFirebird.DoRun;
var
ErrorMsg: String;
ibconnection : TIBconnection;
query : TSqlQuery;
sqltransaction : TSQLTransaction;
username, password : string;
begin
// quick check parameters
ErrorMsg:=CheckOptions('h','help');
if ErrorMsg<>'' then begin
ShowException(Exception.Create(ErrorMsg));
Terminate;
Exit;
end;
// parse parameters
if HasOption('h','help') then begin
WriteHelp;
Terminate;
Exit;
end;
{ add your program here }
IbConnection := TIBConnection.Create(nil);
sqltransaction := tSqltransaction.Create(nil);
query := tsqlquery.Create(nil);
ibconnection.UserName:= 'sysdba';
ibconnection.Password:= 'masterkey';
ibconnection.HostName:= 'localhost';
ibconnection.DatabaseName:='userdatabase';
ibconnection.Transaction := sqltransaction;
query.DataBase := ibconnection;
try
ibconnection.Open;
ibconnection.close;
ibconnection.DropDB;
except
end;
ibconnection.CreateDB;
query.SQL.Add('CREATE TABLE userpassword (username varchar(64) not null,password varchar(64) not null);');
query.ExecSQL;
sqltransaction.CommitRetaining;
query.SQL.clear;
query.sql.Add('insert into userpassword values(''user'',''pass'')');
query.ExecSQL;
sqltransaction.CommitRetaining;
writeln('please give your username');
readln(username);
writeln('please give your password');
readln(password);
writeln('you username is '+ username + ' and your password is ' + password);
query.sql.clear;
query.sql.add('select * from userpassword where username = '''+username +''' and password = ''' +password + ''';');
// or
{ query.sql.add('select * from userpassword where username = '''?''' and password = '''?''';';
query.Params[0] := username;
query.params[1] := password; }
query.Open;
query.First;
while not query.EOF do
begin
writeln('username '+ query.Fields[0].AsString);
query.Next;
end;
if query.RecordCount> 0 then
begin
writeln('credentials passed');
end
else
begin
writeln('access denied');
end;
readln;
// stop program loop
Terminate;
end;
constructor TestFirebirdConsoleUsernameFirebird.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException:=True;
end;
destructor TestFirebirdConsoleUsernameFirebird.Destroy;
begin
inherited Destroy;
end;
procedure TestFirebirdConsoleUsernameFirebird.WriteHelp;
begin
{ add your help code here }
writeln('Usage: ',ExeName,' -h');
end;
var
Application: TestFirebirdConsoleUsernameFirebird;
begin
Application:=TestFirebirdConsoleUsernameFirebird.Create(nil);
Application.Title:='TestFirebirdConsoleUsernameFirebird';
Application.Run;
Application.Free;
end.