Results 1 to 20 of 53
- 01-21-2013, 04:38 PM #1
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
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.
- 01-21-2013, 04:56 PM #2
Senior Member
- Join Date
- Oct 2011
- Location
- Sweden
- Posts
- 123
- Rep Power
- 0
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.
- 01-21-2013, 05:10 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 01-21-2013, 05:19 PM #4
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
Re: password/input masking in terminal
i have some problems understanding the Console class.
like this one I found in a website.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.
also does not work properly.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(); } } }
I also dont undrstand the null concept of the class Console.
- 01-21-2013, 05:52 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 01-21-2013, 05:53 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 01-21-2013, 08:21 PM #7
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
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?
- 01-22-2013, 09:48 AM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 01-22-2013, 02:41 PM #9
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
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}
- 01-22-2013, 02:49 PM #10
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 01-22-2013, 03:20 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: password/input masking in terminal
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.
- 01-22-2013, 04:13 PM #12
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
Re: password/input masking in terminal
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.
- 01-22-2013, 04:18 PM #13
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
Re: password/input masking in terminal
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.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
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
- 01-22-2013, 04:19 PM #14
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
- 01-22-2013, 04:47 PM #15
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 01-22-2013, 05:00 PM #16
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
Re: password/input masking in terminal
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.
- 01-22-2013, 06:00 PM #17
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: password/input masking in terminal
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?
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.
- 01-23-2013, 03:19 PM #18
Member
- Join Date
- Jan 2013
- Location
- Kolkata,India
- Posts
- 59
- Rep Power
- 0
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
ideally, the terminal window should open. But nothing happens. what do you suggest?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; }
- 01-23-2013, 03:27 PM #19
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 01-23-2013, 03:56 PM #20
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
Similar Threads
-
Help with password masking, please
By krechlich in forum New To JavaReplies: 10Last Post: 03-18-2011, 11:28 AM -
input masking 24hour time format (hh:nn) to jTextField
By newbiejava in forum New To JavaReplies: 2Last Post: 07-24-2010, 01:12 PM -
Masking password for logging
By firewalll in forum New To JavaReplies: 1Last Post: 09-29-2009, 08:04 AM -
how to check password for 3 times enterd wrong password
By sk.mahaboobbhasha@gmail.c in forum New To JavaReplies: 2Last Post: 11-14-2008, 07:53 PM -
Creating a dialog to input user/password
By prfalco in forum New To JavaReplies: 4Last Post: 02-18-2008, 07:03 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks