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
    Posts
  • 12757

    hans
    Keymaster

    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 ...
    
    function TfmMain.VerifyAdminLogin:boolean;
    var
      status:OSStatus;
      authRef: AuthorizationRef;
      authFlags: AuthorizationFlags;
      authRights: AuthorizationRights;
      authItem: AuthorizationItem;
    begin
      authItem.flags := 0;
      authItem.name := 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;
    end;        
Viewing 1 post (of 1 total)



You must be logged in to reply to this topic.