Я хочу добавить аутентификацию пользователя в свой applescript для выполнения какой-то задачи. Если имя пользователя и пароль верны, должно произойти только следующее задание. Как это сделать с помощью яблочного скрипта?
Добавление аутентификации пользователя с помощью Applescript
Ответы (3)
Вы действительно не сказали, сколько безопасности вы хотите.
Самое основное из решений:
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
Сохраните его как скрипт только для чтения, и он не позволит случайным пользователям просматривать содержимое скрипта, но на самом деле это совсем не безопасно, если кто-то действительно хочет взломать вашу защиту.
person
indragie
schedule
06.03.2010
Нет, я не хочу проверять имя пользователя и пароль таким образом. Я хочу проверить введенное пользователем имя пользователя и пароль против имени пользователя и пароля текущего пользователя из системы.
- person Shakti; 06.03.2010
Если ваш 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.
Если у вас есть какие-либо вопросы, просто спросите меня :)
person
fireshadow52
schedule
16.07.2011
Непонятно, почему вы запускаете
history -c
и текст после него, кажется, выдает мне ошибку. Вы не хотите очищать свою историю, если вы действительно не хотите... очистить свою историю.
- person tripleee; 12.06.2019
Если вы хотите ввести имя пользователя и пароль, используйте это:
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
person
macscripter
schedule
13.11.2017
извините, я не знаю, как проверить его против системы, системный пароль зашифрован, и поэтому его было бы почти невозможно получить.
- person macscripter; 15.11.2017