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

查看:33
本文介绍了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 运行命令(使用 stdin 作为输入),如果密码不正确会失败

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天全站免登陆