Authentication Applescript检查密码是否正确

Authentication Applescript检查密码是否正确,authentication,applescript,prompt,Authentication,Applescript,Prompt,我正在制作一个需要root权限的应用程序。我是applscript新手,如果这是一个愚蠢的问题,我向您道歉,但我要做的是检查密码是否正确。我从如下提示中获取密码字符串: 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

我正在制作一个需要root权限的应用程序。我是applscript新手,如果这是一个愚蠢的问题,我向您道歉,但我要做的是检查密码是否正确。我从如下提示中获取密码字符串:

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)
在继续之前,我需要检查
密码是否实际上是他们的密码。我不想只使用默认密码提示。有办法做到这一点吗


我已经尝试了一个try,on error语句来测试密码,如果输入的密码不正确,它只会以默认提示提示输入密码。

好的,我就是这样解决的: 1) 在变量中获取密码

2) 尝试使用sudo运行命令(使用stdin作为输入),如果密码不正确,此操作将失败

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

不知道您想做什么,但是如果您想使用sudo执行shell脚本,您应该这样做

do shell script shellScriptVariable with administrator privileges
在shell脚本中没有“sudo”。如果密码错误,您将自动获得一个错误对话框