1
votes

I am making an app that requires root privileges. I am new to applscript and apologize if this is a dumb question but what I am trying to do is check whether a password is correct. I get the password string from a prompt like this:

set thePass to the text returned of (display dialog "I need you to enter your password" default answer "" buttons {"Okay"} default button 1 with icon file ((path to resource "Icon.icns") as text) with hidden answer)

I need to check whether thePass is actually their password before proceeding. I do not want to just use the default password prompt. Is there a way to do this?

I already tried a try, on error statement to test the password, it just prompts for the password with the default prompt if the one entered is incorrect.

2

2 Answers

2
votes

Okay here is how I just solved it: 1) Get the password in a variable

2) Try to use sudo to run a command (using stdin as input), this will fail if the password is incorrect

try
    do shell script "echo '" & thePass & "' | sudo -S :"
onerror
    display alert "Incorrect Password!"
end try
1
votes

No idea what you're trying to do, but if you want to execute a shell script using sudo you should do

do shell script shellScriptVariable with administrator privileges

without the "sudo" in the shell script. You'll automatically get an error dialog if the password is wrong.