控制台窗口中的密码屏蔽和java中的递归函数调用

发布于 2024-10-16 16:37:08 字数 4867 浏览 1 评论 0原文

以下 java 代码在 DR.java IDE 的控制台窗口中执行。 我有以下两个问题,请朋友们帮助我。

  1. 是否可以进行密码屏蔽?我通过谷歌搜索尝试了很多,但没有一个对我有用(应该只使用控制台窗口来执行)。
  2. 当我调用“GetLoginDetails();”时在“ShowAdminMainMenuFun(String EmpName)”方法中,它显示错误([行:148]错误:未处理的异常类型java.io.IOException)。 我想过制作递归函数,但它不起作用,你可以更正编码并将其发回吗?

谢谢你朋友

{
import java.io.*;
import java.awt.*;
import java.io.Console;
import java.util.Scanner;

/*
UserLoginAuthentiction UserLoginAuthentictionObj = new UserLoginAuthentiction();
UserLoginAuthentictionObj.GetLoginDetails();
*/

class UserLoginAuthentiction
{
  static String EmployeeID,Password;
  public static byte resultRole = 0;
  public static void main(String[] args) throws Exception 
  {
    GetLoginDetails();   // it works well here but not works when called againin the following code
  }
  static void GetLoginDetails() throws IOException
  {
    Scanner sc = new Scanner(System.in);
    byte resultRole = 0;
    byte CountForLogin = 0;
    System.out.println("Totally 3 attempts ");  

    do
    {

      if(CountForLogin<3){
      System.out.print("\nEnter User Name:");
      EmployeeID = sc.nextLine();

      System.out.print("Enter Password :");



      Password = sc.nextLine();



      resultRole = ValidateUserIDAndPassword(EmployeeID,Password);
      // if result is zero then the login is invalid,
      // for admin it is one , 
      // for quality analyser it is 2 
      // for project developer it is 3 
      // for developer it is 4
      if(resultRole==0)
      {
        System.out.println("Username & Password does not match ");    
        System.out.print("Retry ::");
        CountForLogin++;
        if(CountForLogin>2)
        {System.out.println("ur attempts are over is locked");}

      }
      else
      {
        System.out.println("here t should call the appropriate employe function");

        GetRoleAndAssignFun(EmployeeID,resultRole);
        break;
      }
      }
    }while(resultRole==0);
  }
  static byte ValidateUserIDAndPassword(String EmployeeID,String Password)
  {

    byte resultRole = 0;

    if((EmployeeID.equals("tcs"))&&(Password.equals("tcs")))
    {
       resultRole = 1;

    }

    /*

     Code for checking the arraylist and returning the validations
     this method should return the roles of the users password

     */

    return resultRole;
  }
  static void GetRoleAndAssignFun(String EmpName ,int EmpRole)
  {   
    // System.out.println("  ");  
    switch(EmpRole)
    {
      case 1:
        System.out.println(" hi " +EmpName+ " u are logged in as admin ");
        ShowAdminMainMenuFun(EmpName);
        break;
      case 2:
        System.out.println(" hi " +EmpName+ " u are logged in as QA ");
        //  QualityAnalyserMainMenu(EmpName);
        break;
      case 3:
        System.out.println(" hi " +EmpName+ " u are logged in as PM ");
        //  ProjectMAnagerMainMenu(EmpName);
        break;
      case 4:
        System.out.println(" hi " +EmpName+ " u are logged in as DEVeloper ");
        //  DeveloperMainMenu(EmpName);
        break;
      default:
        //  System.out.println(EmpName +" You dont have any roles asigned ");
        break;
    }       
  } 


  public static void ShowAdminMainMenuFun(String EmpName)
  {   
    Scanner sc = new Scanner(System.in);
    int loop_option=0;
    do
    {

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

      System.out.println(" Hi "+ EmpName + " you can perform task ussing the menu given below");

      System.out.println("press the appropriate option only");
      System.out.println("1.Create New Employe Profile ");
      System.out.println("2.See Employee's Profile ");
      System.out.println("3. LogOut ");

      System.out.println("Enter the Option u need:");               
      int  option = sc.nextInt();
      switch(option)
      {
        case 1:
          System.out.println("1.Creating New Employe Profile");
          //CreateNewEmployeeProfile();
          break;
        case 2:
          System.out.println("2.See Employee's Profile ");
          //  ViewEmployeeProfile();
          break;
        case 3:
          System.out.println("3. LogOut");
          System.out.println("Do u want to continue logging out  ?? If yes Press 1  ..");
          boolean ConformLogout = false;

          ConformLogout = sc.nextBoolean();
          if(ConformLogout)
          {
            **GetLoginDetails();**   //**** error is here */ how can i call this function please help me
          }
          else
          {

          }
          //   LogOut();
          break;        
        default :
          System.out.println(" You .. ");
      }
      System.out.println("Do u want to continue to main menu ?? Press 1 to continue..");
      loop_option = sc.nextInt();
    }while(loop_option==1);     
  }  


}
}

the following java code is executed in the console window in DR.java IDE.
i have the following two problems please help me friends.

  1. Is it possible to make password masking ?? i tried a lot by googling but none worked for me (should use only console window for excecution).
  2. When i call the "GetLoginDetails();" inside the "ShowAdminMainMenuFun(String EmpName)" method it is showing error ([line: 148] Error: Unhandled exception type java.io.IOException).
    i thought of making recursive function but it dint worked can u correct the coding and post it back.

thanking u friends

{
import java.io.*;
import java.awt.*;
import java.io.Console;
import java.util.Scanner;

/*
UserLoginAuthentiction UserLoginAuthentictionObj = new UserLoginAuthentiction();
UserLoginAuthentictionObj.GetLoginDetails();
*/

class UserLoginAuthentiction
{
  static String EmployeeID,Password;
  public static byte resultRole = 0;
  public static void main(String[] args) throws Exception 
  {
    GetLoginDetails();   // it works well here but not works when called againin the following code
  }
  static void GetLoginDetails() throws IOException
  {
    Scanner sc = new Scanner(System.in);
    byte resultRole = 0;
    byte CountForLogin = 0;
    System.out.println("Totally 3 attempts ");  

    do
    {

      if(CountForLogin<3){
      System.out.print("\nEnter User Name:");
      EmployeeID = sc.nextLine();

      System.out.print("Enter Password :");



      Password = sc.nextLine();



      resultRole = ValidateUserIDAndPassword(EmployeeID,Password);
      // if result is zero then the login is invalid,
      // for admin it is one , 
      // for quality analyser it is 2 
      // for project developer it is 3 
      // for developer it is 4
      if(resultRole==0)
      {
        System.out.println("Username & Password does not match ");    
        System.out.print("Retry ::");
        CountForLogin++;
        if(CountForLogin>2)
        {System.out.println("ur attempts are over is locked");}

      }
      else
      {
        System.out.println("here t should call the appropriate employe function");

        GetRoleAndAssignFun(EmployeeID,resultRole);
        break;
      }
      }
    }while(resultRole==0);
  }
  static byte ValidateUserIDAndPassword(String EmployeeID,String Password)
  {

    byte resultRole = 0;

    if((EmployeeID.equals("tcs"))&&(Password.equals("tcs")))
    {
       resultRole = 1;

    }

    /*

     Code for checking the arraylist and returning the validations
     this method should return the roles of the users password

     */

    return resultRole;
  }
  static void GetRoleAndAssignFun(String EmpName ,int EmpRole)
  {   
    // System.out.println("  ");  
    switch(EmpRole)
    {
      case 1:
        System.out.println(" hi " +EmpName+ " u are logged in as admin ");
        ShowAdminMainMenuFun(EmpName);
        break;
      case 2:
        System.out.println(" hi " +EmpName+ " u are logged in as QA ");
        //  QualityAnalyserMainMenu(EmpName);
        break;
      case 3:
        System.out.println(" hi " +EmpName+ " u are logged in as PM ");
        //  ProjectMAnagerMainMenu(EmpName);
        break;
      case 4:
        System.out.println(" hi " +EmpName+ " u are logged in as DEVeloper ");
        //  DeveloperMainMenu(EmpName);
        break;
      default:
        //  System.out.println(EmpName +" You dont have any roles asigned ");
        break;
    }       
  } 


  public static void ShowAdminMainMenuFun(String EmpName)
  {   
    Scanner sc = new Scanner(System.in);
    int loop_option=0;
    do
    {

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

      System.out.println(" Hi "+ EmpName + " you can perform task ussing the menu given below");

      System.out.println("press the appropriate option only");
      System.out.println("1.Create New Employe Profile ");
      System.out.println("2.See Employee's Profile ");
      System.out.println("3. LogOut ");

      System.out.println("Enter the Option u need:");               
      int  option = sc.nextInt();
      switch(option)
      {
        case 1:
          System.out.println("1.Creating New Employe Profile");
          //CreateNewEmployeeProfile();
          break;
        case 2:
          System.out.println("2.See Employee's Profile ");
          //  ViewEmployeeProfile();
          break;
        case 3:
          System.out.println("3. LogOut");
          System.out.println("Do u want to continue logging out  ?? If yes Press 1  ..");
          boolean ConformLogout = false;

          ConformLogout = sc.nextBoolean();
          if(ConformLogout)
          {
            **GetLoginDetails();**   //**** error is here */ how can i call this function please help me
          }
          else
          {

          }
          //   LogOut();
          break;        
        default :
          System.out.println(" You .. ");
      }
      System.out.println("Do u want to continue to main menu ?? Press 1 to continue..");
      loop_option = sc.nextInt();
    }while(loop_option==1);     
  }  


}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叹沉浮 2024-10-23 16:37:08

关于你的第一个问题,

可以设置密码吗
屏蔽?

您可以使用 java.io.Console 类在控制台窗口上隐藏密码。

Regarding your first question,

Is it possible to make password
masking?

You can use java.io.Console class to hide the password on console window.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文