Below is my java coding that i have done,but i have no idea how to save the password after key in the user id and the password.and i also need the system able to unsave the password if the user choose to unsave it .
Hope you guys will able to help me solve this problem.
import java.util.Scanner;
public class Home {
private static Scanner sc;
public Scanner readPass;
static String savedName="";
static String savedPass="";
public static void main (String []args)
{
String saveQuestion="";
boolean saveError=true;
boolean correctCombi=true;
sc = new Scanner (System.in);
String password=savedPass,name=savedName;
int x=0;
int y=0;
String[] userName={"a","b","c","d","e","f","g"};
String[] secret={"1","2","3","4","5","6","7"};
while(true)
{
do
{
System.out.print("Enter name : ");
name = sc.next();
for (int j=0;j<7;j++)
{
if (userName[j].equals(name))
{
x=j;
break;
}
else x=123;
}
System.out.print("Enter password: ");
password= sc.next();
for (int j=0;j<7;j++)
{
if (secret[j].equals(password))
{
y=j;
break;
}
else y=124;
}
System.out.println(x);
System.out.println(y);
if(x==y)
{
correctCombi= true;
System.out.println("Correct");
}
else
{
System.out.println("ID and Password does not match.");
System.out.println("Please try again");
correctCombi= false;
}
}while(correctCombi!=true);
do
{
System.out.println("Do you want to save this password");
saveQuestion = sc.next();
if (saveQuestion.equals("yes"))
{
savedName= name;
savedPass= password;
saveError=false;
break;
}
else if (saveQuestion.equals("no"))
{
savedName="";
savedPass= "";
saveError=false;
break;
}
else
{
saveError=true;
System.out.println("Please try again");
}
}
}
}
private static Readable Readable(String savedName2) {
// TODO Auto-generated method stub
return null;
}
}