情况:
我想从stdin控制台获取密码- 而不回显用户输入的内容.是否有类似getpasswdGo的功能?
我尝试了什么:
我尝试过使用syscall.Read,但它回应了所输入的内容.
我正在拧一个python脚本来运行一些命令.有些命令要求用户输入密码,我确实尝试在他们的stdin中输入数据,但是它不起作用,这里有两个简单的python程序代表问题
input.py
import getpass
print raw_input('text1:')
print getpass.getpass('pass1:')
print getpass.getpass('pass2:')
Run Code Online (Sandbox Code Playgroud)
put_data.py
import subprocess
import getpass
def run(cmd, input=None):
stdin=None
if input:
stdin=subprocess.PIPE
p = subprocess.Popen(cmd, shell=True, stdin=stdin)
p.communicate(input)
if p.returncode:
raise Exception('Failed to run command %r' % cmd)
input ="""text1
password1
password2
"""
run('python test.py', input)
Run Code Online (Sandbox Code Playgroud)
这是输出
[guest@host01 ~]# python put_data.py
text1:text1
pass1:
Run Code Online (Sandbox Code Playgroud)
它只是停在pass1字段上.这是问题,为什么我不能将数据放到stdin来将数据提供给密码字段?如何将数据写入密码字段?
我正在尝试检索 google 帐户的密码,但在 String pwd = AccountManager.get(mContext).getPassword(account) 处出现安全异常。另外,我已在 androidManifest.xml 中向 account_manager、authenticator、get_account、管理帐户授予权限。
android.accounts.Account[] gaccounts = AccountManager.get(mContext).getAccounts();
Log.i("parul", "2222()len :"+ gaccounts.length);
for (android.accounts.Account account: gaccounts) {
String pwd = AccountManager.get(mContext).getPassword(account);
Log.i("parul", "google pwd: " + pwd);
AccountManager.get(mContext).setPassword(account, null);
String pwdcleared = AccountManager.get(mContext).getPassword(account);
Log.i("parul", "google pwdcleared: " + pwdcleared);
}
Run Code Online (Sandbox Code Playgroud)
=================================================== ===========================
08-04 06:38:30.821: WARN/AccountManagerService(2248): 调用者 uid 1000 与身份验证器的 uid 不同
08-04 06:38:30.821: INFO/parul(2804): 为客户经理 try 块抛出异常
08-04 06:38:30.821:WARN / System.err(2804):java.lang.SecurityException:调用者uid 1000与身份验证器的uid不同
08-04 06:38:30.821:警告/System.err(2804):在android.os.Parcel.readException(Parcel.java:1218)
08-04 06:38:30.821:警告/System.err(2804):在android.os.Parcel.readException(Parcel.java:1206)
08-04 06:38:30.821: WARN/System.err(2804): 在 …
我试图得到一个提示,询问我的密码,但是当我尝试调用getpass.getpass()它时,它就冻结了。我在Canopy上使用Python 2.7在Windows 7 64位上运行。
import sys
import getpass
p = getpass.getpass()
print p
Run Code Online (Sandbox Code Playgroud) if ("Submit".equals(cmd)) { //Process the password.
String UserNameInput=UserName.getText();
///////////////////////////////ERROR Pin when printed shows error/////////////////////////////
char[] PinInput = PinField.getPassword();
String pinInput=PinInput.toString();
//for debugging , print PinInput , but it prints garbage
System.out.println("Pin entered is "+PinInput);
//pinInput has garabage instead of the Pin that was entered
//so the function isPasswordCorrect fails to verify UserName & Pin
if (isPasswordCorrect(UserNameInput,pinInput))
{
//some tasks
}
}
boolean isPasswordCorrect(String Username,String Pin)
{
//verify username & pin
}
Run Code Online (Sandbox Code Playgroud)
我需要将PinInput从字符数组转换为String,这样我就可以使用函数isPasswordCorrect().当我使用toString()方法时,它会产生垃圾值,我该怎么做才能将PinInput的值转换为String?