NetRexx get password hidden? (masked by ***)

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

NetRexx get password hidden? (masked by ***)

Michael (maillists) Dag

Is there a way in NetRexx to get the password hidden from the console? Like ask.hidden()

 

Michael

www.mqsystems.com


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: NetRexx get password hidden? (masked by ***)

Jason Martin
java.io.Console

On Mon, Jul 10, 2017 at 3:51 AM, maillists (@MQSystems) <[hidden email]> wrote:

Is there a way in NetRexx to get the password hidden from the console? Like ask.hidden()

 

Michael

www.mqsystems.com


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/




_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: NetRexx get password hidden? (masked by ***)

Michael (maillists) Dag

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

 

www.mqsystems.com

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Jason Martin
Sent: maandag 10 juli 2017 17:45
To: IBM Netrexx <[hidden email]>
Subject: Re: [Ibm-netrexx] NetRexx get password hidden? (masked by ***)

 

java.io.Console

 

On Mon, Jul 10, 2017 at 3:51 AM, maillists (@MQSystems) <[hidden email]> wrote:

Is there a way in NetRexx to get the password hidden from the console? Like ask.hidden()

 

Michael

www.mqsystems.com


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

 


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: NetRexx get password hidden? (masked by ***)

Jason Martin
In reply to this post by Jason Martin

On Mon, Jul 10, 2017 at 11:44 AM, Jason Martin <[hidden email]> wrote:
java.io.Console

On Mon, Jul 10, 2017 at 3:51 AM, maillists (@MQSystems) <[hidden email]> wrote:

Is there a way in NetRexx to get the password hidden from the console? Like ask.hidden()

 

Michael

www.mqsystems.com


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: NetRexx get password hidden? (masked by ***)

alansam
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.
Reply | Threaded
Open this post in threaded view
|

Re: NetRexx get password hidden? (masked by ***)

Jason Martin
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:
java.io.Console

On Mon, Jul 10, 2017 at 3:51 AM, maillists (@MQSystems) <[hidden email]> wrote:

Is there a way in NetRexx to get the password hidden from the console? Like ask.hidden()

 

Michael

www.mqsystems.com


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/