Check text answer with login password AppleScript

568 views Asked by At

I need a way to check the inputted text from a dialogue box with the computer's login password. Let me explain: I am creating an AppleScript application that will clear up space on the users computer. In order to do so I will need to delete orphaned/useless files and folders. On most macs however, one would need a password to remove certain files. In the beginning of the application, I have placed a dialog box asking for the password. One major problem with this method is that people might believe that this program is a virus and enter an incorrect password, rendering my program useless. Is there some AppleScript command that could check the inputted text with the login password (I have no intention of knowing the password personally)? This way, if they enter a false password they would have to keep inputting it until they input the correct one. If it helps at all my beginning code is below: (Keep in mind that I am using AppleScript)

display dialog "Please enter login password to continue:" default answer "" buttons     {"Submit"} with title "Enter password" with icon stop with hidden answer
...
1

There are 1 answers

0
adayzdone On BEST ANSWER

If the user is an administrator, you could try something like this:

set usr to short user name of (system info)

repeat
    display dialog "Please enter login password to continue:" default answer "" buttons {"Submit"} with title "Enter password" with icon stop with hidden answer
    set pswd to text returned of the result
    try
        do shell script "echo test" user name usr password pswd with administrator privileges
        exit repeat
    end try
end repeat