2013-11-21 59 views
1

我正在製作一個需要root權限的應用程序。我是新來的applscript和道歉,如果這是一個愚蠢的問題,但我想要做的是檢查密碼是否正確。我得到一個提示密碼字符串是這樣的:Applescript檢查密碼是否正確

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

好這裏是如何我只是解決了它: 1)獲取一個變量

2)儘量使用sudo來運行一個命令(使用標準輸入爲輸入)的密碼,這將失敗,如果密碼是不正確

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

不知道你想要做什麼,但如果你想使用sudo來執行shell腳本,你應該做

do shell script shellScriptVariable with administrator privileges 

沒有「命令」中的shell腳本。如果密碼錯誤,您將自動獲得錯誤對話框。