Is there a way in NetRexx to get the password hidden from the console? Like ask.hidden() Michael _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
java.io.Console On Mon, Jul 10, 2017 at 3:51 AM, maillists (@MQSystems) <[hidden email]> wrote:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Found some Java myself but don’t like it and cannot change it right now as I am not a Java programmer… (and don’t want to either!) Say ‘Password: ‘ When typing four characters show four ‘*’ for example **** The one I found works with PasswordField and EraserThread but prints an ‘*’ at the prompt line and so when entering four characters you see actually five which might lead you to believe you entered the wrong password… [code_sample] import java.io.*; public class testpass { public static void main(final String[] args) { String password = PasswordField.readPassword("Enter password:\n\b"); System.out.println("\nPassword entered was:" + password); } } class PasswordField { public static String readPassword (String prompt) { EraserThread et = new EraserThread(prompt); Thread mask = new Thread(et); mask.start(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String password = ""; try { password = in.readLine(); } catch (IOException ioe) { ioe.printStackTrace(); } et.stopMasking(); return password; } } class EraserThread implements Runnable { private boolean stop; private int cnt = 1; public EraserThread(String prompt) { System.out.print(prompt); } public void run () { while (!stop){ cnt = cnt + 1; if (cnt != 2 ) System.out.print("\010*"); try { Thread.currentThread().sleep(1); } catch(InterruptedException ie) { ie.printStackTrace(); } } } public void stopMasking() { this.stop = true; } } [/code_sample] Michael From: [hidden email] [mailto:[hidden email]] On Behalf Of Jason Martin java.io.Console On Mon, Jul 10, 2017 at 3:51 AM, maillists (@MQSystems) <[hidden email]> wrote:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
In reply to this post by Jason Martin
On Mon, Jul 10, 2017 at 11:44 AM, Jason Martin <[hidden email]> wrote:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
This post was updated on .
In reply to this post by Michael (maillists) Dag
One of the biggest benefits of NetRexx is it's ability to leverage the "huge" Java API without needing to learn Java programming.
Here's a worked example of using java.io.Console to hide password inputs: Options replace format comments java symbols Import java.io cons = System.console() pw = Rexx who = 'Michael' count = 1 -- the Java way pw = cons.readPassword('Enter password #%02d for %s: ', [Object Long(count), who]) say String.format('Password #%02d is: %s', [Object Long(count), pw]) -- the Rexx way count = count + 1 say 'Enter password #' || count.right(2, '0') 'for' who': \0' pw = cons.readPassword() say 'Password #' || count.right(2, '0') 'is:' pw Return
Alan
-- Needs more cowbell. |
In reply to this post by Jason Martin
Just for kicks. A charva example. import charva.awt. import charvax.swing. class IBM5250 public extends charvax.swing.JFrame implements charva.awt.event.ActionListener properties private prompt = charvax.swing.JLabel passwd = charvax.swing.JPasswordField reveal = charvax.swing.JButton showit = charvax.swing.JLabel system = charvax.swing.JButton method IBM5250 prompt = charvax.swing.JLabel() prompt.setText("Enter User Password:") passwd = charvax.swing.JPasswordField() passwd.setColumns(10) passwd.setText("") reveal = charvax.swing.JButton() reveal.setText("User Entered") reveal.addActionListener(this) showit = charvax.swing.JLabel() showit.setText("") system = charvax.swing.JButton() system.setText("Exit") system.setActionCommand("Exit"); system.addActionListener(this) setDefaultCloseOperation(charvax.swing.JFrame.EXIT_ON_CLOSE) getContentPane().setLayout(charvax.swing.BoxLayout(getContentPane(), charvax.swing.BoxLayout.Y_AXIS)) getContentPane().add(prompt) getContentPane().add(passwd) getContentPane().add(reveal) getContentPane().add(showit) getContentPane().add(system) pack() setVisible(1) method actionPerformed( evt=charva.awt.event.ActionEvent ) actionCommand = evt.getActionCommand() if actionCommand.equals("Exit") then do exit end else do showit.setText(passwd.getPassword()) passwd.setText("") end method main( args=String[] ) static x=IBM5250() On Mon, Jul 10, 2017 at 11:44 AM, Jason Martin <[hidden email]> wrote:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Free forum by Nabble | Edit this page |