/// Unit UAuth: Authentication-Service mit Interface-Implementierung. /// Testet: uses, interface (mit GUID), Klasse mit Vererbung + Interface, /// Sichtbarkeitsbereiche (private/public), Felder, Properties, /// Methoden, Constructor, Destructor, Funktionsaufrufe. unit UAuth; interface uses System.SysUtils, System.Classes; type /// Interface für Token-Validierung ITokenValidator = interface ['{11111111-1111-1111-1111-111111111111}'] function Validate(const AToken: string): Boolean; end; /// Auth-Service mit Token-Validierung TAuthService = class(TInterfacedObject, ITokenValidator) private FToken: string; FLoginCount: Integer; procedure IncLoginCount; protected function GetToken: string; public constructor Create; destructor Destroy; override; function Validate(const AToken: string): Boolean; function Login(const AUser, APass: string): string; property Token: string read GetToken; property LoginCount: Integer read FLoginCount; end; implementation { TAuthService } constructor TAuthService.Create; begin inherited Create; FToken := ''; FLoginCount := 0; end; destructor TAuthService.Destroy; begin FToken := ''; inherited Destroy; end; procedure TAuthService.IncLoginCount; begin Inc(FLoginCount); end; function TAuthService.GetToken: string; begin Result := FToken; end; function TAuthService.Validate(const AToken: string): Boolean; begin Result := AToken <> ''; end; function TAuthService.Login(const AUser, APass: string): string; begin IncLoginCount; if Validate(AUser + ':' + APass) then begin FToken := AUser; Result := 'ok'; end else Result := ''; end; end.