Name & Password Verification

Hi to you all
I ha a little App that will shutdown the computer - no questions asked.
it starts with a window asking for the user name and password.
but I can’t find a way to verify them and to make sure it is of an Admin or root user.

Yarnin

Would this work?

try
	do shell script "echo ''" with administrator privileges
	tell application "System Events" to shut down
on error errorMsg number errorNum
	if errorNum is not -128 then ¬
		display dialog "Error: " & errorMsg buttons {"Cancel"} default button 1
end try

This way, the system will ask for a name and password itself.

Model: Mac mini
AppleScript: 1.10
Browser: Safari 412
Operating System: Mac OS X (10.4)

I forgot to say…

but the Ithing is that it will ask for the name and password for a later use.
after it asks for the name and password it will ask for a date and time to shut the computer down.
that is done with a shell script with administratore privileges, and name and password instad of the sudo comand.
so the first window asking forthe name and password is for 2 purposes. the first to verify admin is runing the App.
the second is for the shell script.

Yarnin

So, why not do it like this?

try
	do shell script "your_script" with administrator privileges
on error errorMsg number errorNum
	if errorNum is not -128 then ¬
		display dialog "Error: " & errorMsg buttons {"Cancel"} default button 1
end try

Are you saying that you also need to give the password to the shell script?

The shell script will be executed at night when no one is at the oficce. it will shutdown the computer regardless of any operation is being done or documents unsaved.
so the error thing has to be done will the person is running the App. for the first time.
allso I need to store the name and password for later use so.
I can’t run the script apon complition of the name and password window becouse the all thing of the App. is to set futer date to execut the script.

Yarnin

You should use Keychain scripting. First, validate that the user has an admin password then, if so, store it in a new Keychain key (never store it in your script or the script’s preferences). When you need to do something with authentication, retrieve the Key from the Keychain, run your scripts, and immediately clear the variable holding the password. There are plenty of threads on the boards for using Keychanin scripting (though there may have been some subtle changes in AS on Mac OS X 10.4.x if this is applicable to you).

Jon