Applescript检查密码是否正确

时间:2013-11-21 17:48:47

标签: 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 resource "Icon.icns") as text) with hidden answer)

在继续操作之前,我需要检查thePass是否真的是他们的密码。我不想只使用默认密码提示。有没有办法做到这一点?

我已经尝试过,在错误语句上测试密码,如果输入的密码不正确,它只会提示输入默认提示密码。

2 个答案:

答案 0 :(得分:2)

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

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

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

答案 1 :(得分:1)

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

do shell script shellScriptVariable with administrator privileges

在shell脚本中没有“sudo”。如果密码错误,您将自动收到错误对话框。