import java.util.Scanner;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileWriter;
public class Registration {
private void register() throws FileNotFoundException
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter User Name: ");
String Uname=sc.nextLine();
System.out.println(Uname);
System.out.println("Enter Password: ");
String Pass=sc.nextLine();
System.out.println(Pass);
System.out.println("Confirm Password: ");
String ConPass=sc.nextLine();
System.out.println(ConPass);
Uname=Uname.trim();
Pass=Pass.trim();
ConPass=ConPass.trim();
String x= Uname+" "+Pass;
if(Pass.equals(ConPass))
{
File f = new File("Registration.txt");
Scanner content = new Scanner(f);
int flag=0;
while (content.hasNextLine()) {
String data = content.nextLine();
if(data.equals(x))
{
System.out.println("Already Registered");
flag=1;
System.out.println("1. Registration. ");
System.out.println("2. Login. ");
System.out.println("Enter your Choice");
int choice=sc.nextInt();
if(choice==1)
{
this.register();
}
else if(choice==2)
{
this.login();
}
else
{
System.out.println("Choose Proper Option");
}
break;
}
content.close();
}
if(flag==0)
{
try {
BufferedWriter out = new BufferedWriter(new FileWriter("Registration.txt", true));
out.write(Uname+" "+Pass+"\n");
out.close();
}
catch (IOException e) {
System.out.println("exception occoured" + e);
}
System.out.println("Successfully Registered");
System.out.println("Please login");
this.login();
}
}
else
{
System.out.println("Recheck");
System.out.println("1. Registration. ");
System.out.println("2. Login. ");
System.out.println("Enter your Choice");
int choice=sc.nextInt();
if(choice==1)
{
this.register();
}
else if(choice==2)
{
this.login();
}
else
{
System.out.println("Choose Proper Option");
}
}
sc.close();
}
public void login()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter User Name: ");
String Uname=sc.nextLine();
System.out.println(Uname);
System.out.println("Enter Password: ");
String Pass=sc.nextLine();
System.out.println(Pass);
Uname=Uname.trim();
Pass=Pass.trim();
String x= Uname+" "+Pass;
try {
File f = new File("Registration.txt");
Scanner content = new Scanner(f);
int flag=0;
while (content.hasNextLine()) {
String data = content.nextLine();
if(data.equals(x))
{
System.out.println("Login Successful");
System.out.println("Welcome to the Application.");
flag=1;
break;
}
}
if(flag==0)
{
System.out.println("Login Failed");
System.out.println("1. Registration. ");
System.out.println("2. Login. ");
System.out.println("Enter your Choice");
int choice=sc.nextInt();
if(choice==1)
{
this.register();
}
else if(choice==2)
{
this.login();
}
else
{
System.out.println("Choose Proper Option");
}
}
content.close();
}
catch (FileNotFoundException e) {
System.out.println("Error.");
e.printStackTrace();
}
sc.close();
}
public static void main(String[] args) throws FileNotFoundException{
try {
File obj = new File("Registration.txt");
if (obj.createNewFile())
{
System.out.println("File is created");
}
}
catch (IOException e)
{
System.out.println("An error occurred.");
e.printStackTrace();
}
int choice;
Scanner sc=new Scanner(System.in);
System.out.println("1. Registration. ");
System.out.println("2. Login. ");
System.out.println("Enter your Choice");
choice=sc.nextInt();
sc.nextLine();
if(choice==1)
{
Registration user = new Registration();
user.register();
}
else if(choice==2)
{
Registration user = new Registration();
user.login();
}
else
{
System.out.println("Choose Proper Option");
}
sc.close();
}
}
Output:
- Registration.
- Login.
Enter your Choice
1
Enter User Name:
Yash Jain
Yash Jain
Enter Password:
abcd
abcd
Confirm Password:
abcd
abcd
Successfully Registered
Please login
Enter User Name:
Yash Jain
Yash Jain
Enter Password:
abcd
abcd
Login Successful
Welcome to the Application.
- Unlocking Innovation and Diversity: Accenture HackDiva Empowers Women in Tech with Cutting-Edge Solutions – codewindow.in
- QA Engineer Opportunities at Siemens Company: Apply Now – codewindow.in
- QA Engineer Opportunities at Siemens Company: Apply Now – codewindow.in
- Software Engineer Positions at Siemens Company: Apply Now – codewindow.in
- Cloud Engineer II Opportunities at Insight Company: Apply Now – codewindow.in
- Shape Your Career: Assistant Engineer Opportunities at Jindal Company – codewindow.in
- Shape Your Future: Executive Opportunities at Jindal Company – cdewindow.in
- Associate Engineer, Software Development at Ingram: Apply Now – codewindow.in
- Jade Company’s UI/UX Development Engineer Opportunities – Apply Now – codewindow.in
- Transform Your Career with S&P Global: Apply for the Software Development Engineer Role and Lead the Future of Financial Technology Innovation – codewindow.in
- Unlock Your Potential at Accenture as an Associate Software Engineer – Elevate Your Career with Innovation and Excellence – codewindow.in
- Accelerate Your Career: Join NVIDIA’s Elite Software Engineering Internship Program and Shape the Future of Technology – codewindow.in
- C Programming Interview Questions – codewindow.in
- Lead the Way in Analytics: Specialist Position at Razorpay – codewindow.in
- Innovate with Cyient: Junior Software Engineer Wanted – codewindow.in
- Innovate with Volvo: Associate Software Engineer Wanted – codewindow.in
- Lead the Tech Revolution: Full Stack Developer at Unisys – codewindow.in
- Software Engineer at ABB: Unlock Innovation and Shape the Future – codewindow.in
- IBM Associate Systems Engineer Job: Boost Your Career with a Leading Technology Giant – codewindow.in
- Make Your Mark in Android Development: Join Concentrix – codewindow.in
- Infosys is Growing: Field Services Developer Role Now Open – codewindow.in
- Start Your IT Career Journey with Amazon: IT Services Support Associate I Opportunity – codewindow.in
- Shape the Future of Web: Front-End Software Engineer Opportunity at Google Cloud – codewindow.in
- Barclays QA Team Expands: QA Analyst Role Now Open- codewindow.in
- Eurofins QA Team Grows: Test Engineer Role Now Open – codewindow.in
- Exciting Opportunity: Java Spring Boot Senior Developer Role at Infosys – codewindow.in
- Unlock Your Potential at Nokia: Software Engineer Opportunities Await – codewindow.in
- Join Microsoft’s World-Class Team as a Software Engineer and Shape the Future of Technology – codewindow.in
- Virtusa is Seeking Talented React JS Developers to Drive Digital Excellence – codewindow.in
- Join IBM Dynamic Team as a Full Stack Developer and Shape the Future – codewindow.in
- EY Welcomes Aspiring AI/ML Interns to Unlock the Future of -codewindow.in
- Exciting Opportunity: Project Engineer at Rockwell Automation- codewindow.in
- Be at the Nexus of Technology & Finance: Associate Software Engineer at Goldman Sachs – codewindow.in
- Wipro is Hiring Test Engineers to Elevate Quality Assurance – codewindow.in
- Deloitte Is Hiring: Analysts and Senior Analysts Wanted to Drive Innovation – codewindow.in
- Exciting Software Development Opportunity At Oracle – codewindow.in
- BlackBerry Hiring System Software Developer – off campus – codewindow.in
- Lenskart hiring IT Support – off campus – codewindow.in
- Bold Hiring Software Engineer-UI – codewindow.in
- Myntra Hiring Software Engineer – off campus drive – codewindow.in
- PayPal Hiring Data Analyst 1 – codewindow.in
- SIEMENS HEALTHINEERS Hiring Data Scientist ( ML & AI) – codewindow.in
- RELX Digital hiring Software Engineer I – codewindow.in
- KPMG hiring Full Stack Developer Analyst – codewindow.in
- KPMG Hiring for Software Engineer – off Campus – codewindow.in
- Previous Year Coding Questions Suggestion Paper – codewindow.in
- Programming in C++ – codewindow.in
- Programming in C++ – codewindow.in
- Unstop Hiring Challenges Internships and Hackathons – codewindow.in
- Programming in Python – codewindow.in