我想在我的AppleScript添加用戶身份驗證來執行一些任務的用戶認證。如果用戶名和密碼是正確的,那麼只有下一個任務應該發生。如何使用applescript做到這一點?添加使用AppleScript
0
A
回答
0
你真的沒有說你要多少安全性。
最基本的解決方案:
display dialog "Enter username:" default answer ""
set enteredUsername to text returned of result
display dialog "Enter password:" default answer ""
set enteredPassword to text returned of result
if enteredUsername is "CORRECTUSERNAME"
if enteredPassword is "CORRECTPASSWORD"
-- do something
end if
end if
保存爲只讀腳本,它會阻止普通用戶從看劇本的內容,但這不是真的安全可言,如果有人真的想要突破你的保護。
0
如果您的Mac正在運行Leopard(Mac OS X 10.5+),那麼您可以使用system info
命令的long user name
屬性,該命令返回當前用戶的全名。說了這麼多,你可以這樣做......
set the current_user to (get the long user name of (system info)) as string
set the input_password to the text returned of (display dialog "Please enter the password for " & the current_user & ":" default answer "" buttons{"OK"} default button 1 with hidden answer) --The user cannot bypass this dialog.
--The 'hidden answer' property, when true, changes every character you type in the dialog box into ◘'s.
try
--This next line will verify that the password entered matches the current user's password.
do shell script "history -c" user name the current_user password the input_password with administrator privileges
on error --incorrect password
display dialog "Sorry. You entered the wrong password." buttons{"Cancel"}
end try
--Put whatever you want to do after authentication here.
如果您有任何問題,只是問我:)
-2
如果你想要一個用戶名和密碼輸入,然後使用該命令:
set a to the text returned of (display dialog "Please enter your username" default answer "")
set b to the text returned of (display dialog "Please enter your password" default answer "")
if a="username" then --set the username to your username
if b="password" then --set the password to your password
--what ever is after your password protection
end if
end if
+0
對不起,我不知道如何檢查它對系統,系統密碼是加密的,所以它幾乎是無法得到。 – macscripter 2017-11-15 03:34:59
相關問題
- 1. 使用Applescript將郵件內容添加到Excel中
- 2. 使用AppleScript向XCode添加文件,框架和庫4
- 3. 問:使用AppleScript添加文件夾操作
- 4. 將AppleScript添加到Bash腳本中
- 5. 的AppleScript(或SWIFT)添加小時時間
- 6. 添加一個數字到變量applescript
- 7. AppleScript:將菜單添加到地址簿
- 8. 使用AppleScript
- 9. 使用AppleScript
- 10. 使用AppleScript
- 11. 使用AppleScript
- 12. 使用AppleScript
- 13. 使用AppleScript
- 14. 使用AppleScript
- 15. 使用AppleScript
- 16. 使用AppleScript
- 17. 使用AppleScript
- 18. 使用AppleScript
- 19. 使用AppleScript增加mac上的音量?
- 20. 無法在applescript中使用新的applescript
- 21. 如何使用AppleScript
- 22. 嘗試使用AppleScript
- 23. 使用pngquant和AppleScript
- 24. 創建使用AppleScript
- 25. 使用AppleScript打字
- 26. 點擊使用AppleScript
- 27. 獲取使用AppleScript
- 28. 無法使用AppleScript
- 29. 在碼頭上使用AppleScript爲應用程序添加自定義菜單項
- 30. 爲可編寫腳本的應用程序添加AppleScript命令
不,我不想檢查這樣的用戶名和密碼。我想根據當前用戶的用戶名和密碼從系統中檢查用戶輸入的用戶名和密碼。 – Shakti 2010-03-06 11:47:18