Question: How would I create a login/register program in Java using a text file? Program will read from the text file to see if user exists

How would I create a login/register program in Java using a text file? Program will read from the text file to see if user exists and can successfully login at the login screen. If not, they would need to create a user through another GUI then once user creates an account it will add the user to the text file. Below is what I have so far,

Code:

How would I create a login/register program in Java using a text

Login screen

file? Program will read from the text file to see if user

Text file example:

exists and can successfully login at the login screen. If not, they

// method that check if username and password exist in the file public static boolean login(String user, String pass) { // creating object of file class File file = new File("UserList.txt"); FileReader fr; // variable to store login result boolean Login = false; try fr = new FileReader (file); BufferedReader br = new BufferedReader (fr); String line; // reading from file and checks if it matches with file while ((line br.readLine() != null) { String[] split = line.split(", "); String username; String password; split[0]; password = split[1]; } username = } return Login; } = true; public static ArrayList getUsersList() { ArrayList userList = new ArrayList>(); if (username.equals(user) && password. equals(pass)) { Login break; } return userList; } public static void adduser() { } // if entry not exist in the file it will add to the file private void addUserToFile(String username, String password) { if (! Login) { try Files.write(Paths.get("UserList.txt"), (username + StandardOpenOption. APPEND); } catch (IOException e) { } + password).getBytes(), Welcome! Please login to continue. Username: Password: Login No Account? Create Account UserList - Notepad File Edit Format View Help e User123, Password123 -. s Test13, Pass321 it Testing123, password it Username212, password1| it

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!