Applescript 检查密码是否正确

编程入门 行业动态 更新时间:2024-10-18 06:05:22
本文介绍了Applescript 检查密码是否正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在制作一个需要 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-17 14:08:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/915848.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是否正确   密码   Applescript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!