암호와 사용자 이름을 두 개의 개별 파일 (그에 따라 이름 지정)에 저장하고 설정할 수있는 로그인 프로그램을 코딩하고 있습니다. 내 문제는 사용자 이름을 암호로 설정하는 방법을 알 수 없다는 것입니다. 예 : 사용자 이름은 Bob이고 암호는 cat이며 사용자는 Bob을 사용자 이름으로 입력하고 cat은 암호로 입력해야합니다. 그렇지 않으면 오류가 발생합니다 (사용자가 bill이라는 사용자 이름과 cat을 암호로 입력하면 cat 사용자 이름은 각각의 암호와 함께 전달되지 않습니다). 어떤 도움이라도 좋을 것입니다. * 사용자 이름 부분을 아직 추가하지 않았습니다. 암호 부분과 동일하게 구성되었으므로 암호와 일치하는 사용자 이름이 필요하므로 사용자가 동일한 암호로 다른 사용자 이름을 사용할 수 없습니다.JAVA 사용자 이름과 로그인 암호를 일치 시키십시오.
여기 내 내가 참조를 위해 지금까지 가지고 코드 :
import java.io.File;
import java.io.PrintStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.FileReader;
import java.io.*;
import java.util.*;
import javax.swing.JOptionPane;
public class PassCode
{
static String adminPassword = "Change Password";
public static void fileMaker() throws IOException
{
PrintStream standard = System.out;
File f = new File("Password.txt");
FileOutputStream fs= new FileOutputStream(f);
PrintStream ps = new PrintStream(fs);
System.setOut(ps);
String theMessage = "Set New Password";
String userInput = JOptionPane.showInputDialog(theMessage);
System.out.println(userInput);
ps.close();
System.setOut(standard);
}
public static void Checker() throws IOException
{
Scanner inputStream = new Scanner(new FileReader("Password.txt")); //Scans declared file for text on the first line
String fileChecker = inputStream.nextLine(); //Sets scanned line into a string variable
if(fileChecker.isEmpty())
{
fileMaker();
}
else
{
int reply = JOptionPane.showConfirmDialog(null, "Would you like to change the current password", "Warning!", JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.YES_OPTION)
{
String inquire = "Type Administrator Password to Proceed";
boolean flag = true;
while(flag == true)
{
String confirm = JOptionPane.showInputDialog(inquire);
if(confirm.equals(adminPassword))
{
fileMaker();
flag = false;
}
else
{
inquire = "Incorrect!" + "\n" + "Retry";
}
}
}
}
}
public static void main(String[] args) throws IOException
{
Checker();
Scanner inputStreamThree = new Scanner(new FileReader("Password.txt"));
String line = inputStreamThree.nextLine();
String question = "Password Please";
Boolean right = true;
while(right == true)
{
String ask = JOptionPane.showInputDialog(question); //Asks for user to input password
if(ask.equals(adminPassword)) //Checks if user input the admin password
{
fileMaker();
Scanner inputStreamAdmin = new Scanner(new FileReader("Password.txt")); //Scans for admin password
String adminChecker = inputStreamAdmin.nextLine(); //Sets scanned line as a new string variable
line = adminChecker;
}
else if(line.equals(ask)) //Checks if user password is correct
{
System.out.println("Welcome Fellow Programmer to the Now Functioning Password Checker!" +
"\n" + "Date Today: 10/31/2017" +
"\n\n\n\n\n\n\n" + "Did you figure out the Admin password yet?");
right = false;
}
else if(ask != line) //Checks if user password is incorrect
{
question = "Incorrect Password!";
}
}
}
}
데 두 개의 서로 다른 파일 요구 사항 : 여기
내가 추가 한 코드합니다 (LNR 그냥 방법)은? –선호되지만, 다른 방법이 있다면 괜찮을 것입니다. 또한 두 개의 서로 다른 파일을 사용하여 비밀번호와 사용자 이름을 따로 저장하려고했습니다. –