Добавление аутентификации пользователя с использованием Applescript - PullRequest
0 голосов
/ 03 марта 2010

Я хочу добавить аутентификацию пользователя в мой appleScript, чтобы выполнить какую-то задачу. Если имя пользователя и пароль верны, то должно произойти только следующее задание. Как это сделать с помощью яблочного сценария?

Ответы [ 3 ]

0 голосов
/ 16 июля 2011

Если ваш Mac работает под управлением Leopard (Mac OS X 10.5+), вы можете использовать свойство long user name команды 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.

Если у вас есть какие-либо вопросы, просто спросите меня:)

0 голосов
/ 13 ноября 2017

Если вы хотите ввести имя пользователя и пароль, используйте это:

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 голосов
/ 06 марта 2010

Вы действительно не сказали, какую безопасность вы хотите.

Самые основные решения:

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

Сохраните его как сценарий только для чтения, и он не позволит обычным пользователям просматривать содержимое сценария, но это совсем не безопасно, если кто-то действительно хочет взломать вашу защиту.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...