-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateaccount.java
More file actions
136 lines (122 loc) · 3.29 KB
/
createaccount.java
File metadata and controls
136 lines (122 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class createaccount {
static int f1=0;
public static void main(String[] args) throws IOException {
Scanner obj=new Scanner(System.in);
String admin=new String("admin");
String user =new String("user");
String s;
int ch;
while(true)
{
System.out.println("1.for admin\n2.user\n3 login ");
ch=obj.nextInt();
switch(ch)
{
case 1:
{
System.out.println("the admin user name is by default " +"admin");
FileOutputStream fout=new FileOutputStream("C:\\Users\\MANSA\\javafile\\admin.txt");
BufferedOutputStream bout=new BufferedOutputStream(fout);
Scanner obj1=new Scanner(System.in);
System.out.println("enter the password");
s=obj1.nextLine();
byte b[]=s.getBytes();
bout.write(b);
bout.flush();
bout.close();
fout.close();
System.out.println("success");
break;
}
case 2:
{
System.out.println("the user name is by default " +"user");
FileOutputStream fout=new FileOutputStream("C:\\Users\\MANSA\\javafile\\user.txt");
BufferedOutputStream bout=new BufferedOutputStream(fout);
Scanner obj2=new Scanner(System.in);
System.out.println("enter the password");
s=obj2.nextLine();
byte b[]=s.getBytes();
bout.write(b);
bout.flush();
bout.close();
fout.close();
System.out.println("Success");
break;
}
case 3:
{
Scanner obj3=new Scanner(System.in);
int t;
System.out.println("enter 1 if you are admin and 2 if you are user\n");
t=obj3.nextInt();
switch(t)
{
case 1:
{
Scanner obj4=new Scanner(System.in);
System.out.println("Password: ");
String obj1=new String(obj4.nextLine());
BufferedReader m =new BufferedReader(new FileReader("C:\\Users\\MANSA\\javafile\\admin.txt"));
String Line= new String();
try {
while((Line=m.readLine())!=null)
{
if(obj1.equals(Line))
{
f1=0;
break;
}
else
f1=1;
}
} catch (IOException e) {
e.printStackTrace();
}
if(f1==0)
System.out.println("Password is correct.");
else
System.out.println("Password incorrect.");
break;
}
case 2:
{
Scanner obj5=new Scanner(System.in);
System.out.println("Password: ");
String obj1=new String(obj5.nextLine());
BufferedReader m =new BufferedReader(new FileReader("C:\\Users\\MANSA\\javafile\\user.txt"));
String Line= new String();
try {
while((Line=m.readLine())!=null)
{
if(obj1.equals(Line))
{
f1=0;
break;
}
else
f1=1;
}
} catch (IOException e) {
e.printStackTrace();
}
if(f1==0)
System.out.println("Password is correct.");
else
System.out.println("Password incorrect.");
break;
}
}
}
case 4:
break;
}
}
}
}