<br><font size=2 face="sans-serif">With IronPython, this </font>
<br>
<br><font size=2 face="Courier New">import getpass</font>
<br><font size=2 face="Courier New">pwd = getpass.getpass()</font>
<br>
<br><font size=2 face="sans-serif">do'nt work properly, because the password
will be echoed.</font>
<br>
<br><font size=2 face="sans-serif">I worked about this problem. The NET-platform
probably doesn't have a direct function for getting password from console.
</font>
<br><font size=2 face="sans-serif">I found only this C# example http://www.harper.no/valery/content/binary/ProtectData.cs.txt</font>
<br><font size=2 face="sans-serif">and wrote a simple module net_getpass.py
which contains a function getpass(). </font>
<br><font size=2 face="sans-serif">For those who have the same problem,
here is the source:</font>
<br>
<br><font size=2 face="sans-serif">------------------------------------------------------------
source -------------------------------------------------------------------------------</font>
<br><font size=2 face="Courier New">'''</font>
<br><font size=2 face="Courier New">Module net_getpass</font>
<br><font size=2 face="Courier New">Getting password from console in IronPython
(Python.NET)</font>
<br>
<br><font size=2 face="Courier New">Author: Roman Miklos (RMiklos@pss.sk)</font>
<br><font size=2 face="Courier New">'''</font>
<br><font size=2 face="Courier New">import clr</font>
<br><font size=2 face="Courier New">import System</font>
<br><font size=2 face="Courier New">from System import Console</font>
<br>
<br>
<br><font size=2 face="Courier New">def getpass(prompt=&quot;Password:&quot;):</font>
<br><font size=2 face="Courier New">&nbsp; '''Read Password from Console
without echo'''</font>
<br><font size=2 face="Courier New">&nbsp; # Prompt</font>
<br><font size=2 face="Courier New">&nbsp; Console.Write(prompt)</font>
<br><font size=2 face="Courier New">&nbsp; # create Instance of ConsoleKeyInfo</font>
<br><font size=2 face="Courier New">&nbsp; key = System.ConsoleKeyInfo()</font>
<br><font size=2 face="Courier New">&nbsp; # initialize vars</font>
<br><font size=2 face="Courier New">&nbsp; pwd =&quot;&quot;</font>
<br><font size=2 face="Courier New">&nbsp; EnterPressed = False</font>
<br><font size=2 face="Courier New">&nbsp; # Read while input not ends</font>
<br><font size=2 face="Courier New">&nbsp; while not EnterPressed:</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; key = Console.ReadKey(True)</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; if key.Key == System.ConsoleKey.Enter:</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; # End of Input</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; EnterPressed =
True</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; </font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; elif key.Key == System.ConsoleKey.Backspace:</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; if len(pwd)&gt;0:</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; # Clear
last character in password &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; pwd = pwd[:-1]</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; Console.Write(key.KeyChar)</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; Console.Write(&quot;
&quot;)</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; Console.Write(key.KeyChar)</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; else:</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; Console.Beep()</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; </font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; else:</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; pwd += key.KeyChar</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; Console.Write(&quot;*&quot;)</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; </font>
<br><font size=2 face="Courier New">&nbsp; # Next line</font>
<br><font size=2 face="Courier New">&nbsp; Console.WriteLine()</font>
<br><font size=2 face="Courier New">&nbsp; # return password</font>
<br><font size=2 face="Courier New">&nbsp; return (pwd)</font>
<br>
<br><font size=2 face="Courier New">################################################################################</font>
<br><font size=2 face="Courier New"># Module Test</font>
<br><font size=2 face="Courier New">################################################################################</font>
<br><font size=2 face="Courier New">if __name__ == &quot;__main__&quot;:</font>
<br><font size=2 face="Courier New">&nbsp; print &quot;Your Password is:
%s&quot; % getpass(&quot;Enter your password please:&quot;) </font>
<br>
<br><font size=2 face="sans-serif">------------------------------------------------------------------
end of source -------------------------------------------------------------------------</font>
<br>
<br><font size=2 face="Courier New">However I don't make usage of .NET
SecureString() object in my module as showed in above C# example,</font>
<br><font size=2 face="Courier New">but for simplicity I used only normal
python string.<br>
Mgr. Ing. Roman MIKLÓ© <br>
Prvá stavebná sporiteµňa a.s. <br>
Bajkalská 30, P. O. Box 48 <br>
829 48 &nbsp;Bratislava 25 <br>
Tel.: +421/ 2 / 582 31 174 <br>
Fax: +421/ 2 / 582 31 109 <br>
</font>