Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mask input in groovy

Tags:

groovy

How can I mask input from the command line? Basic use case: I want to enter a password when prompted, and I need to either see *'s or nothing at all.

like image 395
Zombies Avatar asked Apr 22 '10 20:04

Zombies


People also ask

What does [:] mean in Groovy?

[:] creates an empty Map. The colon is there to distinguish it from [] , which creates an empty List. This groovy code: def foo = [:]

What is password masking?

Password masking is the act of hiding passwords as bullets or asterisks when the user enters the password. Password masking is an attempt to protect the user against shoulder surfers who look at the screen.

How do you comment lines in Groovy?

A multiline comment starts with /* and can be found at any position in the line. The characters following /* will be considered part of the comment, including new line characters, up to the first */ closing the comment. Multiline comments can thus be put at the end of a statement, or even inside a statement.


1 Answers

Since you can call Java libraries from Groovy, you may find your answer in the question How to mask a password in Java 5?.

In short, use Console.readPassword() (Java 6 or later).

like image 145
Greg Hewgill Avatar answered Oct 25 '22 10:10

Greg Hewgill