• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 515
  • Last Modified:

How to insert mask " * " for a password when entering data in java?

I want mask user input for a password field in java, can anyone help??

here r my codes....

import java.sql.*;
import java.io.* ;


public class OrderProcessing {

String ans;
int choice;
static String use1;
static String pass1;

BufferedReader br= new BufferedReader (new InputStreamReader(System.in));


      public void LogInMenu() throws IOException, SQLException{

      int counter=0;

      Statement stmt ;
      ResultSet rs ;
      PreparedStatement pstmt ;
      String query;

      Connect connect1=new Connect();
      stmt=connect1.connect.createStatement() ;

            System.out.print("================================================================================");
            System.out.print("\t\tMAURIWEAR ORDER PROCESSING SYSTEM LOG IN MENU");
            System.out.print("\n================================================================================");


            while (counter<3)
            {
            //for (int i=0; i<5; i++)
          //System.out.println("\n");

            if (counter==0)
            System.out.print(counter+1+ "st Try");
            else if (counter==1)
            System.out.print(counter+1+ "nd Try");
            else
            System.out.print(counter+1+ "rd Try");

            System.out.print("\t\t\tUser Name: ");
            String UserName=br.readLine();

            System.out.print("\n\t\t\tPassword: ");
            String Password=br.readLine();


            query = "select EmployeeID from Employee where UserName+Password ='"+ UserName + Password+"'";

          rs = stmt.executeQuery(query) ;

          if (rs.next())
          {      use1=UserName;
                pass1=Password;
                  mainmenu();
            }
            rs.close() ;

            System.out.print("\n\t\tYou are not an Authorised Employee!!!!\n");
            System.out.print("\n================================================================================");
            counter=counter+1;

            }

      }

public static void main(String args[]) throws Exception
      {
            OrderProcessing Ord=new OrderProcessing();

            Ord.LogInMenu();

      }
}
0
SniperVishal
Asked:
SniperVishal
  • 3
  • 3
  • 2
  • +1
2 Solutions
 
RuadRauFlessaCommented:
In console Mode you must be off your rocker. There are not go to commands or anything in Java. People fail to grasp the concept that console output is supposed to be for debugging only. Not for actually accepting user input or giving user output. Go over to Swing or AWT and your problem will be solved. There is even a component specially designed for accepting passwords (JPasswordField) they even took a couple of precautions to make sure that someone who is listening for memory changes cannot readily and without any hassle blindly just read the damn value.
0
 
SniperVishalAuthor Commented:
I tried the method objects said... its seems nice but the user wont know he is typing.... anyways it does the job..
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
objectsCommented:
yeah its a bit of a hack, but its the best u can do
0
 
objectsCommented:
try replacing the print in the thread with:

System.out.print("\010*");
0
 
RuadRauFlessaCommented:
Nice one objects.
0
 
girionisCommented:
I think points should be split between me and objects.
0
 
RuadRauFlessaCommented:
I would agree with girionis on that.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now