Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting text from password field

Tags:

java

Hello I am trying to create a login form in java netbeans IDE. My aim is to create multiple user ID's and their respective passwords. I have given textfields to userID and passwordField for passwords to get the values but the problem is i want to get the text from the password field and i am unable to get it its showing some error i think there is some problem with syntax my research is as follows can there be any solution? Need your help

private void lb_loginMouseClicked(java.awt.event.MouseEvent evt) {                                      
       DBUtil util = new DBUtil();
       String value1=tb_uid.getText();
       String value2=tb_pwd.getPassword();
       String user1="";
       String pass1="";
       try {

            Connection con = util.getConnection();
            PreparedStatement stmt = con.prepareStatement("SELECT * FROM login where username='"+value1+"' && password='"+value2+"'");
            ResultSet res = stmt.executeQuery();
            res = stmt.executeQuery();
            while (res.next()) {
                user1 = res.getString("username");
                pass1 = res.getString("password");
            }
            if (value1.equals(user1) && value2.equals(pass1)) {
            JOptionPane.showMessageDialog(this,"correct");
            }
            else{
            JOptionPane.showMessageDialog(this,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
            }
            JOptionPane.showMessageDialog(null, "COMMITED SUCCESSFULLY!");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());

        }

    }  
like image 553
Sumeet Gavhale Avatar asked Jan 04 '13 17:01

Sumeet Gavhale


People also ask

Which text property is used to enter the test as password?

To create a password text box Set the PasswordChar property of the TextBox control to a specific character. The PasswordChar property specifies the character displayed in the text box.

What is the use of setEchoChar () method?

With echo char, you can set a character that would appear whenever a user will type the password in the JPasswordField.

Is a text component specialized for password entry?

The object of a JPasswordField class is a text component specialized for password entry. It allows the editing of a single line of text. It inherits JTextField class.


2 Answers

String pwd = new String(jPasswordField1.getPassword());

Option 1:

jTextField1.setText(""+pwd);

Option 2:

System.out.println(""+pwd);
like image 141
Vishav Jeet Singh Sodhi Avatar answered Oct 17 '22 10:10

Vishav Jeet Singh Sodhi


Use this code:

String password = String.valueOf(jPasswordField.getPassword());

The JPasswordField is encrypted but if you use String.valueOf it will converted Char to String.

like image 44
Richard Flores Avatar answered Oct 17 '22 10:10

Richard Flores