使用 Applescript 添加用户身份验证

发布于 2024-08-23 18:58:06 字数 88 浏览 6 评论 0原文

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

I want to add user authentication in my applescript to perform some task. If the username and password is correct then only the next task should happen. How to do this using applescript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

并安 2024-08-30 18:58:06

你还没有真正说出你想要多少安全性。

最基本的解决方案:

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

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

You haven't really said how much security you want.

The most basic of solutions:

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

Save it as a read-only script and it'll prevent casual users from looking at the contents of the script, but this is not really secure at all if someone really wants to break through your protection.

爱,才寂寞 2024-08-30 18:58:06

如果您的 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.

如果你有任何疑问,请问我:)

If your Mac is running Leopard (Mac OS X 10.5+), then you could use the long user name property of the system info command, which returns the full name of the current user. Having said that, you could do this...

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.

If you have any questions, just ask me :)

往事随风而去 2024-08-30 18:58:06

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

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

If you are wanting a username and password input then use this:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文