Hello there, I have a little applet within which a user is asked for their password. A dialogue box then comes up, and the user types their password. Once they hit OK, I was wondering if it was possible to test to see if the password was typed correctly. Should I do a simple test like do some command which requires the admin password and see if an error comes up, then have the user retype their password? Or is their a simple way to check if the dialogue they typed into the box was actually the correct password. Thanks in advance for your help.
Hi,
you need a routine like this
property userPassword : missing value
repeat
if userPassword is missing value then
set userPassword to text returned of getPassword("Define new password", {"OK"})
set confirmPassword to text returned of getPassword("Confirm password", {"OK"})
if userPassword is confirmPassword then exit repeat
display dialog "No match, try it again" buttons {"OK"} default button 1 giving up after 2
set userPassword to missing value
else
set {button returned:enteredButton, text returned:enteredPassword} to getPassword("Enter your password", {"Cancel", "Reset Password", "OK"})
if enteredButton is "OK" then
if enteredPassword is userPassword then exit repeat
display dialog "Wrong password, try it again" buttons {"Cancel", "Retry"} default button 2
else
set userPassword to missing value
end if
end if
end repeat
on getPassword(thePrompt, theButtons)
return display dialog thePrompt default answer "" buttons theButtons default button ("OK")
end getPassword
Thank you for the prompt script replay Stephan, however I was still wondering if it’s possible to test if the password is ACTUALLY the administrator password, seeing as the application would have to be “idiot” proof, they could accidently supply the password for say, their email address. Is there anyway to test if the password they supply is the admin password by using it to do something that would REQUIRE the admin password and not hurt/modify anything? If that confirmation returned an error with the supplied pass, then it would know that it is not the admin pass, and therefore the user would need to re enter their password.
Thanks again,
dp
You’re obviously asking for a PW because something your script does or calls requires it. Why not put that something in a try block and bounce back on error?
--- get set to do stuff
repeat
try
--ask for password
--do the stuff that requires a PW
exit repeat
on error
--dialog the bad pw
end try
end repeat
-- press on with more stuff
I am still wondering if it is possible to test if a password is correct without bringing up the dialog to enter the correct pw if the test one is incorrect. In Panther (and Leopard?) if you enter an incorrect password in a shell script command, you get this dialog. That’s OK, but the whole process does not return an error. So I cannot think of a way to have the user enter a correct pw (so it can be saved for future use). Perhaps Apple designed AS that way so it is hard to try to find out people’s pw’s? So - is there any shell command requiring admin privileges that would return an error if the wrong pw was used? Alternatively (I am a newbie for AS), is there a way of testing if a certain window has been opened (the one prompting for the correct pw) that would signal to AS that the pw was incorrect?
Thanks for any pointers here. Eric