User authentication in an app

Hi - I am writing an app that has several “default writes” commands to run system tweaks. Since I need to distribute this app across campus, I cannot provide and administrator name and password in the script because they will be different in every department. My solution to this is when launching the app, an authentication dialog should appear for the local administrator.

How can I accomplish this in cocoa?

Thanks in advance,
t.

While not a Cocoa method, something simple like the following might work for you, provided you are writing an AppleScript ObjC application:


try
	do shell script "ls ~/" with administrator privileges
	-- do other things here
on error
	tell me to quit
end try

If you can use do shell script, it’s a lot, lot simpler than the recommended Cocoa way.

Thank you both. I can also use NSTask for this, but I was interested to call this function in Cocoa the way it is done to unlock the PadLock icon in System Preferences which in-turn invokes the authentication dialog.

Thanks,
t.

There’s an authorization API, but it’s C-based and you can’t call it from ASObjC. The way it’s used usually involves launching a separate process with the extra privileges.