如何通过CLI程序获取密码? [英] How to get a password with a CLI program?
本文介绍了如何通过CLI程序获取密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写Linux CLI程序.我需要从用户那里获得密码,并且显然,我不想将密码回显到控制台.
I am writing a Linux CLI program. I need to get a password from the user and, obviously, I don't want the password to be echoed to the console.
这里有几种解决方案,但是它们都是针对纯C语言的.
C命令行密码输入
如何在c中屏蔽密码?
在C语言中使用密码而不使用getpass(3)吗?
There are several solutions available here, but they are all for plain C.
C command-line password input
How to mask password in c?
Getting a password in C without using getpass (3)?
如何使用std :: string而不是char []将其用于C ++?
How can those be adapted for C++, using std::string instead of char[]?
最优雅的C ++解决方案是什么?
What would be the most elegant C++ solution?
推荐答案
使用任何普通的C解决方案:
Use any of the plain C solutions:
std::string pass (100); // size the string at your max password size (minus one)
func_to_get_pass(&pass[0], pass.size());
// function takes a char* and the max size to write (including a null char)
pass.resize(pass.find('\0'));
cout << "Your password is " << pass << ".\n"; // oops! don't show it ;)
这篇关于如何通过CLI程序获取密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文