• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Ant Won't Hide Password

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ant insists on displaying the password I enter for the following task:

<input
addproperty="ftp.password"
message="${line.separator}Ready to deploy JAR.${line.separator}${line.separator}Enter password for ${ftp.user.id}@${ftp.server}:${line.separator}${line.separator}"
/>

Does anyone know a workaround for this, or whether the Ant folks plan to add something like a hide="true" attribute to the <input> task? I toyed with writing a custom task to handle this, but this seems like re-inventing 90% of the wheel.
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This was my solution:

Q. How to hide password input?
A: Override ant Input task.
Response every user input with a backspace. Not the best, but it works.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is annoying that you can only specify a different inputhandler on the ant command line, .antrc, .ant/ant.conf, or /etc/antrc, but you can override it in the build.xml, which means you have to configure every person's workstation separately, and they can just check out the repository and go.

Here is a workaround that works in Linux and presumably any other *nix.


<project name="blah">
<target name="get-login">
<input message="Enter Username:" addproperty="login-props.username"/>

<!-- get the password if it wasn't defined in the login properties file -->
<!-- Turn off echoing of password to terminal.
"-isig" is necessary to prevent you from hitting control-C to
kill ant, and then you are stuck in your terminal which doesn't echo
any of the commands you type.
-->
<exec executable="sh">
<arg line="-c 'stty -echo -isig < /dev/tty'"/>
</exec>
<input message="Enter Password:" addproperty="login-props.password"/>
<exec executable="sh">
<arg line="-c 'stty echo isig < /dev/tty'"/>
</exec>

<echo message="Username: ${login-props.username}" />
<echo message="Password: ${login-props.password}" />
</target>
</project>

I found out how to turn off the echoing of the password by looking at the source code for jline.
http://jline.sourceforge.net/
 
On my planet I'm considered quite beautiful. Thanks to the poetry in this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic