c++ - 为什么 getpass() 被认为是过时的功能?

标签 c++ unix

我一直在寻找一个 getpass() 替代方法,它实际上是我创建的隐藏密码输入的最简单方法。对于 C++ 来说,这是一种损失,因为它是一种如此简单的函数,却有很多用途。

我想知道的是为什么它被认为已过时,它是否存在任何安全问题?

我仍然可以/应该专业地使用它,无视警告并将其视为“夸大”吗?

最佳答案

Why is getpass() considered an obsolete function?

根据 this man page

The getpass() function is not threadsafe because it manipulates global signal state.

The getpass() function is scheduled to be withdrawn from a future version of the X/Open CAE Specification.


can/should i still use it professionally

如果您的 C 库具有该函数,那么您可以使用它。

如果您考虑以下任何一项:缺乏线程安全性,或总体上对全局信号状态的操纵,或者作为一个过时的函数,它可能会在符合 future 的 C 库的 future 版本中被删除POSIX 版本,有问题,那你不应该使用它。


推荐的替代方法是编写您自己的函数,使用 termios 并禁用 ECHO 标志。在 glibc manual 中完成最小替代.

关于c++ - 为什么 getpass() 被认为是过时的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34945808/

相关文章:

c++ - boost 错误 : reference to 'detail' is ambiguous

c++ - MFC 序列化双向链表

当我插入元素时,C++ 优先级队列崩溃

linux - 帮助 Unix 中的文件描述符

linux - 难以解决:- “SCP copies files successfully, but files not visible in local computer”

android - --target native-lib 不是一个目录

c++ - boost hana 将两个序列压缩到 map 中

unix - awk/Unix group by

linux - 如何从文件中逐行读取并执行内部内容

c - 获取用户输入,然后执行 execvp