AppleScript的检查是否密码正确 [英] Applescript Check Whether Password is Correct

查看:355
本文介绍了AppleScript的检查是否密码正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个需要root权限的应用程序。我是新来applscript并道歉,如果这是一个愚蠢的问题,但我所要做的是检查密码是否正确。我从一个提示密码字符串是这样的:

I am making an app that requires root privileges. I am new to applscript and apologize if this is a dumb question but what I am trying to do is check whether a password is correct. I get the password string from a prompt like this:

set thePass to the text returned of (display dialog "I need you to enter your password" default answer "" buttons {"Okay"} default button 1 with icon file ((path to resource "Icon.icns") as text) with hidden answer)

我需要检查是否 thePass 实际上是在继续之前他们的密码。我不想只使用默认的密码提示。有没有办法做到这一点?

I need to check whether thePass is actually their password before proceeding. I do not want to just use the default password prompt. Is there a way to do this?

我已经尝试过一试,对错误语句来测试密码,它只是提示用户提供与如果输入一个不正确,默认提示输入密码。

I already tried a try, on error statement to test the password, it just prompts for the password with the default prompt if the one entered is incorrect.

推荐答案

好吧这里是如何我只是解决了它:
1)在一个变量得到密码

Okay here is how I just solved it: 1) Get the password in a variable

2)尝试使用sudo来运行一个命令(使用标准输入作为输入),这将失败,如果密码不正确

2) Try to use sudo to run a command (using stdin as input), this will fail if the password is incorrect

try
    do shell script "echo '" & thePass & "' | sudo -S :"
onerror
    display alert "Incorrect Password!"
end try

这篇关于AppleScript的检查是否密码正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆