Page 1 of 3 123 LastLast
Results 1 to 20 of 53
  1. #1
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Question password/input masking in terminal

    I am trying to mask the input data that is giving from terminal to a
    java program. In case of password fields kind of things it becomes
    necessary. Through awt/swings I am able to do this but through prompt I want
    it to be done. Is there any way to do this?
    I got a few links of java.io.Console.readPassword class of java but i seem not to understand it t all.
    I also tried to use Command-Line Input Masking but it seem to no avail.please help.

  2. #2
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Location
    Sweden
    Posts
    124
    Rep Power
    0

    Default Re: password/input masking in terminal

    Actually, I don't understand much of what you want to do.

    Mask it into a java program? Parse it?

    Please explain further and in more detailed structure what you want to accomplish.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default Re: password/input masking in terminal

    What do you not understand about the Console class documentation?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    i have some problems understanding the Console class.
    If the virtual machine is started from an interactive command line without redirecting the standard input and output streams then its console will exist and will typically be connected to the keyboard and display from which the virtual machine was launched. If the virtual machine is started automatically, for example by a background job scheduler, then it will typically not have a console.
    like this one I found in a website.
    Java Code:
    import java.io.Console;
    
    public class ConsoleDemo {
       public static void main(String[] args) {
          
          Console cnsl = null;
          String alpha = null;
          
          try{
             // creates a console object
             cnsl = System.console();
    
             // if console is not null
             if (cnsl != null) {
                
                // read line from the user input
                alpha = cnsl.readLine("Name: ");
                
                // prints
                System.out.println("Name is: " + alpha);
                
                // read password into the char array
                char[] pwd = cnsl.readPassword("Password: ");
                
                // prints
                System.out.println("Password is: "+pwd);
             }      
          }catch(Exception ex){
             
             // if any error occurs
             ex.printStackTrace();      
          }
       }
    }
    also does not work properly.
    I also dont undrstand the null concept of the class Console.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default Re: password/input masking in terminal

    It is possible to launch that code without a console.
    For example, as an executable jar using javaw.
    No "physical" console will mean System.console() will return null...there is no console to interact with.

    The example given in that text is for a background job, which has no associated console either.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default Re: password/input masking in terminal

    Oh, and what does "does not work properly" mean?

    You have to give us exact information...we are unlikely to run code you supply, and we also cannot see your computer from here.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    okay I am sorry for that. I just wanted to learn how to hide users input in bluej in the terminal window.So that I can take passwords and other sensitive data..i tried google search and found the CONSOLE CLASS.Have you got any idea how do to this mate?

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default Re: password/input masking in terminal

    So what does not work?
    And by "terminal window" do you mean some part of BlueJ? If so then I suspect it won't work. It doesn't in Eclipse, for example, as it is not a proper console. It's only pretending to be one.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    if it does not work in BlueJ, could you please tell me a method to somehow hide the input given by a user on method call/in the terminal window{Console in others such as Eclipse}

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: password/input masking in terminal

    Any program that needs to be run in BlueJ isn't going to have a super sensitive confidentiality. When you learn to use GUIs, you can mask your password entry by using a JPasswordField.

    Since this isn't a "New to Java" question but rather a BlueJ question, I'm moving it to the "Other IDEs" section.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default Re: password/input masking in terminal

    Quote Originally Posted by harshit shah View Post
    if it does not work in BlueJ, could you please tell me a method to somehow hide the input given by a user on method call/in the terminal window{Console in others such as Eclipse}
    You would (at a guess) have to find a way to interact with this pretend console. That will probably involve learning how the particular IDE you are using actually uses its terminal tab, and then writing some form of plugin maybe? All in all not something you really want to bother delving into as it is not exactly useful and, as Darryl suggests, may as well simply write a proper GUI.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  12. #12
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    Quote Originally Posted by Tolls View Post
    You would (at a guess) have to find a way to interact with this pretend console. That will probably involve learning how the particular IDE you are using actually uses its terminal tab, and then writing some form of plugin maybe? All in all not something you really want to bother delving into as it is not exactly useful and, as Darryl suggests, may as well simply write a proper GUI.
    ok, the case i wan to present is this:
    i had made a gui for my particular program.
    the main purpose of my particular program is to take imput from a single-user so i am not connecting to a database here.
    my purpose is to call a method from the particular Jbutton when it is clicked, and the login is successful...but somehow it does not happen. So i thought a bout taking password from the terminal window in BlueJ itself.
    any idea how i should go about it?
    i will post my code here once as well, in my next post in the thread.

  13. #13
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    Java Code:
    import javax.swing.*;//importing essential p[ackages
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    class Login   extends JFrame implements ActionListener//uses action listener method
    {
    
        public static int success_of_login = 0;
        JButton SUBMIT;//button for submitting data
        JPanel panel;
        JLabel label1,label2,label3;
        JTextField  text1,text2;
        public static void main()
        {
            try//try-catch method
            {
                Loginworker frame=new Loginworker();
                frame.setSize(700,150);
                frame.setLocation(400,400);
                frame.setVisible(true);//showing frame
            }
            catch(Exception e)//exception handler
            {
                System.out.println("JAVA EXEPTION TRIGGERED.PLEASE CHECK FOR YOUR FAULTS");
                System.out.println("FAULTS SUCH AS WRONG INPUTS, WRONG INPUT OR TYPE");
            }
        }
    
        void Loginworker()//initializer+constructor
        {
            label1 = new JLabel();
            label2 = new JLabel();
            label3 = new JLabel();
    
            label1.setText("Username:");
            text1 = new JTextField(15);
            text1.setBackground(Color.yellow); 
    
            label2.setText("Password:");//password field
            text2 = new JPasswordField(15);//from java.awt
            text2.setBackground(Color.red);
    
            SUBMIT=new JButton("login");
    
            panel=new JPanel(new GridLayout(3,1));
    
            panel.add(label1);
            panel.add(text1);
            panel.add(label2);
            panel.add(text2);
            panel.add(label3);
            panel.add(SUBMIT);
    
            add(panel,BorderLayout.CENTER);
            SUBMIT.addActionListener(this);
            setTitle("PLEASE LOGIN");//title bar
        }
    
        public void actionPerformed(ActionEvent ae)//using actionlistener
        {
            String value1=text1.getText();
            String value2=text2.getText();
            //checking inputs
            //and password
            //and username
            if (value1.equals("pratik sanyal") ||value1.equals("pratik") ||value1.equals("pratik sir") && value2.equals("9051232032")||value2.equals("cta")|| value2.equals("pp"))
            {
                JOptionPane.showMessageDialog(this,"WELCOME PRATIK SIR!",
                    "SUCCESS!",JOptionPane.INFORMATION_MESSAGE);
                success_of_login = 1;
                try
                {
                    Main_menu ob = new Main_menu();
                    ob.main_menu();
                }
                catch (Exception E)
                {}
    
            }
            else if (value1.equals("student") && value2.equals(""))
            {
                JOptionPane.showMessageDialog(this,"login successful",
                    "SUCCESS!",JOptionPane.INFORMATION_MESSAGE);
                success_of_login = 1;
            }
            else if (value1.equals("harshit shah") && value2.equals("hrs"))
            {
                JOptionPane.showMessageDialog(this,"WELCOME HARSHIT",
                    "SUCCESS!",JOptionPane.INFORMATION_MESSAGE);
                success_of_login = 1;
            }
            else
            {
                JOptionPane.showMessageDialog(this,"Incorrect login or password",
                    "Error",JOptionPane.ERROR_MESSAGE);
            }
        }//end of method
    
    }//end of class
    in the snippet of code i have pasted here, in the else-if portion, another class method is supposed to be called. But it just does not happen, so i thought i will do away with JFrame.
    P.S. my program should be a simple one, as i will be submitting it as a class project, which is why i want to keep it as simple as possible.
    i have tried to start the method by try-catch, but it wont work.
    i am at loggerheads

  14. #14
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    Quote Originally Posted by DarrylBurke View Post
    Any program that needs to be run in BlueJ isn't going to have a super sensitive confidentiality. When you learn to use GUIs, you can mask your password entry by using a JPasswordField.

    Since this isn't a "New to Java" question but rather a BlueJ question, I'm moving it to the "Other IDEs" section.

    db
    actually the question was right at that time, but seems i have moved on to my particular IDE

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default Re: password/input masking in terminal

    Since the Swing version is the way forward, if you want a hidden password field, when using the JButton, what results do you see?
    What values do you see for value1 and value2.
    (And why on earth are they not username and password?)

    For those values what route through the if/elseif/else should it take?
    What route is it taking?
    If the route is correct then what, exactly, is the problem?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  16. #16
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    Quote Originally Posted by Tolls View Post
    Since the Swing version is the way forward, if you want a hidden password field, when using the JButton, what results do you see?
    What values do you see for value1 and value2.
    (And why on earth are they not username and password?)

    For those values what route through the if/elseif/else should it take?
    What route is it taking?
    If the route is correct then what, exactly, is the problem?
    The problem exactly is, that i cant call another method from the actionlistener i am using.
    answer to why on earth:
    the value 1 and value 2 are storing the values of username and password for comparing to the right username and password. In short, they are just names of 2 variables, so that people may not confuse it all up.

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default Re: password/input masking in terminal

    Quote Originally Posted by harshit shah View Post
    The problem exactly is, that i cant call another method from the actionlistener i am using.
    OK, we might actually be getting somewhere here.
    What method, exactly, are you wanting to call?
    Do you get some compilation error when you try to use it?
    If not then what happens when the code runs?
    What should happen?

    Quote Originally Posted by harshit shah View Post
    answer to why on earth:
    the value 1 and value 2 are storing the values of username and password for comparing to the right username and password. In short, they are just names of 2 variables, so that people may not confuse it all up.
    Then why not call them username and password? Variable names should match what they represent. 'input1' and 'input2' are meaningless and you are in fact making it more likely that people will be confused.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  18. #18
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: password/input masking in terminal

    okay. I will change the variable names but what I want really happens after login success is that i want to run a method from another class.There are no compilation errors but when the other method is invoked from other class it stops taking input at all.my System.out.println statments work but the BufferedReader fails to take input.
    i will provide you with my whole code of all my classes.[after editing value1 and value2 variables to username and password]

    ideally,[P.S my program should be a simple one] a termnial window of bluej should be launched which then takes necessary input from the user.But, it does not happen. nothing happens.
    no compile error crops up, as the code seems to run pretty nicely.

    a snippet of my code
    Java Code:
    if (username.equals("pratik sanyal") ||username.equals("pratik") ||username.equals("pratik sir") && password.equals("9051232032")||password.equals("cta")|| password.equals("pp"))
            {
                try
                {
                    Main_menu.main_menu();
                }
                catch(IOException E) {}
                JOptionPane.showMessageDialog(this,"WELCOME PRATIK SIR!",
                    "SUCCESS!",JOptionPane.INFORMATION_MESSAGE);
                success_of_login = 1;
    }
    ideally, the terminal window should open. But nothing happens. what do you suggest?

  19. #19
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default Re: password/input masking in terminal

    You need to sort out how you explain things.

    You talk about "run a method from another class", but don't actually say what method on what class.

    In that if statement there are no println() calls, so why you say they all work is beyond me. There are none there to actually work. So you have no idea at all if you are even entering this bit of code.
    You are eating an IOException, I notice, which is poor practice. You should at the very least do E.printStackTrace().

    And if you mean you expect the JOptionPane to appear then say so. It is not a "terminal".
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  20. #20
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: password/input masking in terminal

    And three passwords for each user seems strange to me. And that E for the IOException reference is not coding standard.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Page 1 of 3 123 LastLast

Similar Threads

  1. Help with password masking, please
    By krechlich in forum New To Java
    Replies: 10
    Last Post: 03-18-2011, 11:28 AM
  2. input masking 24hour time format (hh:nn) to jTextField
    By newbiejava in forum New To Java
    Replies: 2
    Last Post: 07-24-2010, 01:12 PM
  3. Masking password for logging
    By firewalll in forum New To Java
    Replies: 1
    Last Post: 09-29-2009, 08:04 AM
  4. how to check password for 3 times enterd wrong password
    By sk.mahaboobbhasha@gmail.c in forum New To Java
    Replies: 2
    Last Post: 11-14-2008, 07:53 PM
  5. Creating a dialog to input user/password
    By prfalco in forum New To Java
    Replies: 4
    Last Post: 02-18-2008, 07:03 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •