隐藏用户输入 [英] Hiding User Input

查看:219
本文介绍了隐藏用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获得一个脚本,在本机Windows shell和cygwin shell(通过ssh)提示和读取用户输入的密码。到目前为止,我已经尝试了以下方法:


  1. 使用Term :: ReadKey并将ReadMode设置为'noecho'

    • 结果:返回错误 GetConsoleMode失败并退出


  2. 使用Term :: ReadPassword :: Win32

    • 结果:挂起,从不提供提示或读取输入

    结果:返回一个错误无法写入终端使用IO :: Prompt

      <并退出

  3. 使用Term :: InKey

    • 结果: code>未在MSWin32上实现:句柄无效并退出


所有这些都在本地Windows shell(命令提示符或power shell)中工作,但是当我在到服务器的ssh会话中时,它们都不工作。



真的,这是我最感兴趣的,让它在远程ssh会话中工作。



我通过cygwin获得ssh安装在Windows服务器(2003 R2)上。我使用草莓perl而不是cygwin perl(cygwin perl打破其他perl脚本我需要在Windows本机运行,而不是通过ssh)。



我最好的猜测是cygwin + Windows正在使用草莓perl,它不能告诉它是什么样的环境。我正在寻找替代的sshd + Windows解决方案来探索这个。



这些都是我在搜索中找到的所有方法。其他任何人都有任何其他方法隐藏用户输入他们可以建议?

解决方案

  use Term :: ReadKey; 
print请输入您的工件用户名:;
$ username =< STDIN> ;;
chomp($ username);
ReadMode('noecho'); #do not echo
print请输入您的工件密码:;
$ password =< STDIN> ;;
chomp($ password);
ReadMode(0); #back to normal
print\\\
\\\
;


I'm trying to get a script that works both in a native windows shell and a cygwin shell (via ssh) that prompts for and reads a password entered by the user. So far, I have tried the following methods:

  1. using Term::ReadKey and setting ReadMode to 'noecho'
    • RESULT: returns an error GetConsoleMode failed and quits
  2. using Term::ReadPassword::Win32
    • RESULT: hangs and never offers a prompt or reads input
  3. using IO::Prompt
    • RESULT: returns an error Cannot write to terminal and quits
  4. using Term::InKey
    • RESULT: returns an error Not implemented on MSWin32: The handle is invalid and quits

All of these work in a native Windows shell (command prompt or power shell), but none of them work when I'm in an ssh session to the server.

Really, that's what I'm most interested in, getting it to work in the remote ssh session.

I'm getting ssh via cygwin installed on the Windows server (2003 R2). I'm using strawberry perl and not the cygwin perl (cygwin perl breaks other perl scripts I need to run natively in Windows, not via ssh).

My best guess is that cygwin+Windows is screwing with strawberry perl enough that it can't tell what kind of environment it is in. I'm looking into alternative sshd+Windows solutions to explore this.

These are all the methods I've been able to find in my searching. Does anybody else have any other methods for hiding user input they can suggest?

解决方案

use Term::ReadKey;
print "Please enter your artifactory user name:";
$username = <STDIN>;
chomp($username);
ReadMode('noecho'); # don't echo
print "Please enter your artifactory password:";
$password = <STDIN>;
chomp($password);
ReadMode(0); #back to normal
print "\n\n";

这篇关于隐藏用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆