Verifying a password

I want to ask the user for the root password and verify it before I move on. Im using askPassword from system.osax (thanks to the other thread). How do I verify that I have the correct password? The only way I can think of is to try executing a shell script that would need admin privileges in a try statement, but that seems a bit of a sloppy workaround… If this is the only way, what would be a good shell command to use?


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Apart from the fact your sample doesn’t do what you want, I’m confused as to why you think you need to do this.

For a start, ‘do shell script… with administrator privileges’ uses sudo to execute the command and therefore uses the users password, comparing it to /etc/sudoers to verify the user is allowed to perform the command. Therefore, even if they entered the correct password for ‘do shell script’ to run, that still wouldn’t be the root password.

If you’re planning on using ‘do shell script’ to execute a number of commands with elevated privileges, you don’t need to ask for the password at all - ‘do shell script’ will prompt the user for it, and not execute the commands until a value username/password is entered.

Here’s how to authenticate for the sudo password:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Isn’t the default user for sudo root? (edit: nevermind)

The thing is, the commands I’m issuing through ‘do shell script’ will take a while to run. I wanted to store the root password so that I don’t have to prompt for it each time the timestamp expires.

Jon:
Thank you! I didn’t quite see the applicability of the -k and -v switches when I glanced at the man pages for sudo. One question though: Once I’ve authenticated, will my timestamp run out during a long command? I have a bunch of long running things to do in a row and don’t want to prompt for a password all the time.

Then just use a combo of the askPassword command and the sudo authentication:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Excellent, thanks! I was getting hung up on what to do in the event of an error. I’m still getting the hang of “try” blocks and “on error” events.

Thanks to the posting in this string, I’ve come close to stopping prying eyes into certian folders. I want to password protect a folder and if the password is not given or the user gives up, I’d like the window/ folder to close. As the following code is now, the user can simply hit cancel and they’re in!
Any help would be greatly appreciated
Thanks everyone!

CODE:
on opening folder this_folder
repeat
try
do shell script “sudo -k”
end try
try
do shell script “sudo -v” with administrator privileges
exit repeat
on error the_error
display dialog the_error buttons {“Cancel”, “Try Again”} default button 2 with icon 0
end try
end repeat
return do shell script “sudo ls”
end opening folder
on choosing(“Cancel”)
close this_folder
end choosing