使用Applescript添加用户身份验证

使用Applescript添加用户身份验证,applescript,Applescript,我想在applescript中添加用户身份验证以执行某些任务。如果用户名和密码正确,则只应执行下一个任务。如何使用applescript实现这一点?您还没有真正说明需要多少安全性 最基本的解决方案: display dialog "Enter username:" default answer "" set enteredUsername to text returned of result display dialog "Enter password:" default answer "" s

我想在applescript中添加用户身份验证以执行某些任务。如果用户名和密码正确,则只应执行下一个任务。如何使用applescript实现这一点?

您还没有真正说明需要多少安全性

最基本的解决方案:

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

将其保存为只读脚本,这样可以防止临时用户查看脚本的内容,但如果有人真的想突破您的保护,则根本不安全。

如果您的Mac电脑运行的是Leopard Mac OS X 10.5+,则可以使用system info命令的长用户名属性,返回当前用户的全名。话虽如此,你可以做到这一点

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.

如果您有任何问题,请询问我:

如果您需要用户名和密码输入,请使用以下命令:

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

不,我不想这样检查用户名和密码。我想根据系统中当前用户的用户名和密码检查用户输入的用户名和密码。对不起,我不知道如何根据系统进行检查,系统密码是加密的,因此几乎无法获取。不清楚为什么要运行history-c和文本,因为它似乎为我产生了一个错误。你不想清除你的历史,除非你真的想。。。清除你的历史记录。