Page 1 of 1

Lazarus – macOS – Request Admin Authentication

Lazarus – macOS – Request Admin Authentication

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
Examples: "MacOS X - Your question", "MS Word - Your Tip or Trick".

Please note that switching to another language when reading a post will not work!
Posts will not have a translated counterpart.

RSS Feed

Home Forums Software Development Delphi, Lazarus, Free Pascal Lazarus – macOS – Request Admin Authentication

Viewing 1 post (of 1 total)
  • Author
  • 12757


    Sometimes one needs to verify if the user is admin and has the appropriate right to access a certain function.
    there are under macOS several ways to do this, but to use the proper API call in Lazarus Pascal, you can try this function I created.
    It triggers a Admin authentication request and returns either TRUE or FALSE.

    Uses ... MacOSAll ...
    {$linkframework Security}
    function TfmMain.VerifyAdminLogin:boolean;
      authRef: AuthorizationRef;
      authFlags: AuthorizationFlags;
      authRights: AuthorizationRights;
      authItem: AuthorizationItem;
      authItem.flags := 0; := kAuthorizationRightExecute;
      authItem.value := nil;
      authItem.valueLength:= 0;
      authRights.count := 1;
      authRights.items := @authItem;
      authRef := nil;
      authFlags := kAuthorizationFlagInteractionAllowed or kAuthorizationFlagExtendRights or kAuthorizationFlagPreAuthorize;
      status := AuthorizationCreate(@authRights, kAuthorizationEmptyEnvironment, authFlags, authRef);
      Result := status=errAuthorizationSuccess;
    • This topic was modified 3 months, 4 weeks ago by Hans.
    • This topic was modified 1 month, 2 weeks ago by Hans.
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.