isames
asked on
Java authentication program
All,
I'm a beginner Java programmer. I'm trying to write an authentication program that asks a user to enter credentials in the Main method, and then pass the info the a second method called openCredentials. In the openCredentials method, I first tried to open the credentials file, and then I was going to try and compare input from the Main to what's in the openCredentials method. The file in the openCredentials method is called credentials.txt. I get an error trying to open it. Also I get error with the parameters I'm trying to pass info to. Below is what I have so far. Please help me get started down the right path.
package authenticationsystem;
import java.util.Scanner;
import java.io.*;
import java.util.*;
public class AuthenticationSystem {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner scnr = new Scanner (System.in);
String UserName = "";
String PassWord = "";
System.out.println("Please enter your username. For example: John.Doe"); //Here I'm asking for credentials.
UserName = scnr.next();
System.out.println("You entered: " + UserName);
System.out.println("Please enter your password.");
PassWord = scnr.next();
}
private Scanner X;
public openCredentials(String userName, String passWord){
try{
X = new Scanner (new File ("credentials.txt"));
}
catch(Exception e){
System.out.println("Could not find file");
return;
}
}
}
}
}
I'm a beginner Java programmer. I'm trying to write an authentication program that asks a user to enter credentials in the Main method, and then pass the info the a second method called openCredentials. In the openCredentials method, I first tried to open the credentials file, and then I was going to try and compare input from the Main to what's in the openCredentials method. The file in the openCredentials method is called credentials.txt. I get an error trying to open it. Also I get error with the parameters I'm trying to pass info to. Below is what I have so far. Please help me get started down the right path.
package authenticationsystem;
import java.util.Scanner;
import java.io.*;
import java.util.*;
public class AuthenticationSystem {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner scnr = new Scanner (System.in);
String UserName = "";
String PassWord = "";
System.out.println("Please
UserName = scnr.next();
System.out.println("You entered: " + UserName);
System.out.println("Please
PassWord = scnr.next();
}
private Scanner X;
public openCredentials(String userName, String passWord){
try{
X = new Scanner (new File ("credentials.txt"));
}
catch(Exception e){
System.out.println("Could not find file");
return;
}
}
}
}
}
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
You're going to get compilation errors first
http://technojeeves.com/index.php/aliasjava1/17-errors