我一直在寻找一个 getpass()
替代方法,它实际上是我创建的隐藏密码输入的最简单方法。对于 C++ 来说,这是一种损失,因为它是一种如此简单的函数,却有很多用途。
我想知道的是为什么它被认为已过时,它是否存在任何安全问题?
我仍然可以/应该专业地使用它,无视警告并将其视为“夸大”吗?
最佳答案
Why is getpass() considered an obsolete function?
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/