C命令行输入密码

编程入门 行业动态 更新时间:2024-10-28 04:17:06
本文介绍了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上。所以我不真正关心赢或其他系统。我想卢卡斯的解决方案,它工作得很好。不过,我还有另一个问题:

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:42:02,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1527774.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:命令行   输入密码

    发布评论

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

    >www.elefans.com

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