控制台窗口中的密码屏蔽和java中的递归函数调用
以下 java 代码在 DR.java IDE 的控制台窗口中执行。 我有以下两个问题,请朋友们帮助我。
- 是否可以进行密码屏蔽?我通过谷歌搜索尝试了很多,但没有一个对我有用(应该只使用控制台窗口来执行)。
- 当我调用“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.
- 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).
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于你的第一个问题,
您可以使用 java.io.Console 类在控制台窗口上隐藏密码。
Regarding your first question,
You can use java.io.Console class to hide the password on console window.