C命令行密码输入

编程入门 行业动态 更新时间:2024-10-28 02:32:52
本文介绍了C命令行密码输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想允许用户使用命令行界面输入密码.但我不想在屏幕上显示此密码(或显示****").

I want to allow users to enter password using command-line interface. but I don't want to display this password on screen (or display "****").

如何在C中做到这一点?谢谢.

How to do it in C? Thanks.

更新:

我只在 Linux 上工作.所以我实际上并不关心 Win 或其他系统.我尝试了 Lucas 的解决方案,效果很好.不过,我还有一个问题:

I'm working on Linux only. So I don't actually care about Win or other systems. I tried Lucas' solution and it worked fine. However, I still have another question:

  • 如果这是单个进程&单线程应用,改变termios的设置会影响不同的终端?

  • If this is a single process & single thread app, changing setting of termios affects different terminals?

    1 个进程 - 多线程,多进程 - 多线程怎么样?

    How about 1 process - multi threads, multi processes - multi threads?

    非常感谢.

    推荐答案

    如果您的系统提供,getpass 是一个选项:

    If your system provides it, getpass is an option:

    #include <unistd.h> /* ... */ char *password = getpass("Password: ");

    这不会在输入字符时显示任何内容.

    This will not display anything as characters are typed.

  • 更多推荐

    C命令行密码输入

    本文发布于:2023-10-25 18:41:46,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1527773.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:命令行   密码

    发布评论

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

    >www.elefans.com

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