Rx Database Security

RX Library

Control Name Unit Class
RX Database Security DBSecur TDBSecurity

Description:
The TDBSecurity component provides a quick, standard interface for users to gain access to an database-oriented application. This component provides two standard dialogs: registration (login) dialog and change user password dialog. Specify Database property or call Login method manually to show registration dialog, and call ChangePassword method to show change password dialog.

Also TDBSecurity allows you lock application in minimized state by calling Lock method. After lock user must enter password to unlock and restore application.

Using class TDBSecurity
Set Database, UsersTableName and LoginNameField to approperiate values, write event handler to the OnCheckUser event (if needed) and set Active to True for use standard login dialog when application started.

When UsersTableName and LoginNameField are not specified, you can use this component to connect to the SQL-oriented database.

TDBSecurity provides three standard dialogs for database-oriented applications:
- registration (login) dialog;
- change user password dialog;
- unlock with password dialog for unlock locked application.


Property Active
Declaration: Active: Boolean;

If there any IO access to the data, this is triggered


Property AllowEmptyPassword
Declaration: AllowEmptyPassword: Boolean;
AllowEmptyPassword determines whether or not user can leave password edit box empty in the login dialog and in the change password dialog.


Property AttemptNumber
Declaration: AttemptNumber: Integer;

AttemptNumber is a count of available attempts to input valid user name and password in the login dialog. After user input invalid user name or password more then AttemptNumber times the application halts.


Property Database
Declaration: Database: TDatabase;

Specifies the Database component for which TDBSecurity component provides standard dialogs and login to by calling Login method.


Property LoggedUser
Declaration: LoggedUser: string;

Run-time and read-only property. Returns the user name logged to the database. You can use this property after successfull connection with database or in the handler of OnCheckUser event.

When connection to the database is unsuccess, the LoggedUser property is empty.


Property LoginNameField
Declaration: LoginNameField: string;

The LoginNameField property is a string which represents the name of a field in the table, specified by UsersTableName property. The field in question contains the login name of the user, and in most cases must be the first field in the existing index for the table.


Property MaxPasswordLen
Declaration: MaxPasswordLen: Integer;

The MaxPasswordLen property specifies the maximum number of characters the user can enter in an password edit box in the login dialog and in the change password dialog. The default setting for MaxPasswordLen is 0, which means that there is no limit on the number of characters the password can contain.


Property UpdateCaption
Declaration: UpdateCaption: TUpdateCaption;

UpdateCaption is used to update the Application's title, or form-caption if necessary, to inform the user of something important.


Property UseRegistry
Declaration: UseRegistry: Boolean;

UseRegistry determines whether or not a Windows System Registry will be used (in 32-bit version only) to store data. When UseRegistry is False, data will be store in text INI-file.


Property UsersTableName
Declaration: UsersTableName: TFileName;

The UsersTableName property points to an existing database table, which holds data about the users of the application and their passwords. At the least, the table must have a field representing a login name, specified by LoginNameField property, and optionaly a fields representing a password or any extraneous information, which can be used in the OnCheckUser event handler.


Event AfterLogin
Declaration: AfterLogin: TNotifyEvent;

After the user login, AfterLogin event is triggered.


Event OnChangePassword
Declaration: OnChangePassword: TChangePasswordEvent;

When the user changes the password, OngChangePassword is triggered.

Event OnChangePassword example:

function TMainForm.SecurityChangePassword(UsersTable: TTable; const OldPassword, NewPassword: String): Boolean;
begin
__Result := False;
__if SecurityCheckUser(UsersTable, OldPassword) then
__begin
____with UsersTable do
____begin
______Edit;
______FieldByName('PASSWORD').AsString := CryptString(PswdKey, NewPassword);
______Post;
____Result := True;
____end;
__end;
end;


Event OnCheckUser
Declaration: OnCheckUser: TCheckUserEvent;

Password checking

Event OnCheckUser example:

function TMainForm.SecurityCheckUser(UsersTable: TTable; const Password: String): Boolean;
begin
__Result := False;
__with UsersTable do
__begin
____if CryptString(PswdKey, FieldByName('PASSWORD').AsString) = Password then
____begin
______Result := True;
______UserId := FieldByName('ID').AsInteger;
______UserLevel := FieldByName('USER_LEVEL').AsInteger;
____end;
__end;
end;


Event OnUnlock
Declaration: OnUnlock: TCheckUnlockEvent;

Event OnUnLock is triggered when the table is unlocked.


Method ChangePassword
Declaration: function ChangePassword: Boolean;

Uses the change-password instead.


Method Lock
Declaration: procedure Lock;

procedure locks locks the database.


Method Login
Declaration: function Login: Boolean;

The Login method displays the registration login dialog represented by the component on the screen, try connect to database and check user rights with event OnCheckUser. It's called automatically when Active property is True, and can be called manually. It returns true if the user succesfully logged into database.


Type TChangePasswordEvent
Declaration: TChangePasswordEvent = function(UsersTable: TTable; const OldPassword, NewPassword: string): Boolean of object;

TChangePasswordEvent is the type of the OnChangePassword event of the TDBSecurity component.


Type TCheckUnlockEvent
Declaration: TCheckUnlockEvent = function(const Password: string): Boolean of object;

TCheckUnlockEvent is the type of the OnUnlock event of the TDBSecurity component.


Type TCheckUserEvent
Declaration: TCheckUserEvent = function(UsersTable: TTable; const Password: string): Boolean of object;

TCheckUserEvent is the type of the OnCheckUser event of the TDBSecurity component.


Type TUpdateCaption
Declaration: TUpdateCaption = (ucNoChange, ucAppTitle, ucFormCaption);

The TUpdateCaption is the type for the UpdateCaption property of TDBSecurity component.


Index Page | About | Download
Creation Date: 4 Feb 1998 | Last Update: 16 Mar 2000