-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
191 lines (157 loc) · 5.04 KB
/
Main.java
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package queuecode;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.*;
public class Main
{
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int choice = 0;
do {
System.out.print("Enter username: ");
String username = scanner.nextLine();
boolean valid = isValidUsername(username);
if(valid) {
System.out.print("Enter password: ");
String password = scanner.nextLine();
// Validate the password.
boolean validPassword = validatePassword(password);
// Check if the username and password are valid.
if (validPassword) {
System.out.println("Authentication successful!");
System.out.println("***WELCOME TO MUSICMATCH***");
// takeuserchoice();
String bio = bioip();
String[] lang = lang();
String[] genre = genre();
String[] artist= artist();
User data = new User(username, password, bio, artist, lang, genre);
data.showData();
// Path fileName = Path.of("C:/Users/Dell/Desktop/Competitions/QueueCode/DSACraft/Userdata.txt");
//
// // Writing into the file
// Files.writeString(fileName, data);
//
// // Reading the content of the file
// String file_content = Files.readString(fileName);
//
// // Printing the content inside the file
// System.out.println(file_content);
} else {
System.out.println("Authentication failed.");
}
break;
}
else {
System.out.println("Username invalid!");
System.out.println("Do you want to try with other username?\nYes = 1\tNo = 0");
choice = scanner.nextInt();
scanner.nextLine();
}
}while(choice != 0);
// Object of graph is created.
}
private static String bioip() {
System.out.println("Enter song lyric which best describes you: ");
String bio = scanner.nextLine();
// System.out.println(bio);
return bio;
}
private static String[] lang() {
System.out.println("Languages:\n1. English\n2. Hindi\n3. Marathi\n4. Korean\n5. Thai\n6. Other");
System.out.println("Enter any 2 languages you listen to: ");
String[] lang = new String[3];
for (int i = 0; i < 2; i++) {
lang[i] = scanner.nextLine();
}
return lang;
}
private static String[] genre() {
System.out.println("Genre:\n1. Indie\n2. Rock\n3. Hip Hop\n4. Bollywood\n5. Lo-Fi"
+ "\n6. Electro\n7. New-age\n8. Jazz\n9. Punk\n10. Desi\n11. Kpop\n12. Pop");
System.out.println("Enter any 5 genres you listen to: ");
String[] gen = new String[5];
for (int i = 0; i < 5; i++) {
gen[i] = scanner.nextLine();
}
return gen;
}
private static String[] artist() {
System.out.println("Enter any 3 Artist you listen to: ");
String[] art = new String[3];
for (int i = 0; i < 3; i++) {
art[i] = scanner.nextLine();
}
return art;
}
private static boolean isValidUsername(String name) {
// Regex to check valid username.
String regex = "^[A-Za-z]\\w{5,29}$";
// Compile the ReGex
Pattern p = Pattern.compile(regex);
// If the username is empty
// return false
if (name == null) {
return false;
}
// Pattern class contains matcher() method
// to find matching between given username
// and regular expression.
Matcher m = p.matcher(name);
// Return if the username
// matched the ReGex
return m.matches();
}
private static boolean validatePassword(String password) {
// Check if the password is at least 8 characters long.
if (password.length() < 8) {
return false;
}
// Check if the password contains at least one uppercase letter.
boolean hasUppercaseLetter = false;
for (int i = 0; i < password.length(); i++) {
if (Character.isUpperCase(password.charAt(i))) {
hasUppercaseLetter = true;
break;
}
}
if (!hasUppercaseLetter) {
return false;
}
// Check if the password contains at least one lowercase letter.
boolean hasLowercaseLetter = false;
for (int i = 0; i < password.length(); i++) {
if (Character.isLowerCase(password.charAt(i))) {
hasLowercaseLetter = true;
break;
}
}
if (!hasLowercaseLetter) {
return false;
}
// Check if the password contains at least one digit.
boolean hasDigit = false;
for (int i = 0; i < password.length(); i++) {
if (Character.isDigit(password.charAt(i))) {
hasDigit = true;
break;
}
}
if (!hasDigit) {
return false;
}
// Check if the password contains at least one special character.
boolean hasSpecialCharacter = false;
for (int i = 0; i < password.length(); i++) {
if (!Character.isLetterOrDigit(password.charAt(i))) {
hasSpecialCharacter = true;
break;
}
}
if (!hasSpecialCharacter) {
return false;
}
// The password is valid.
return true;
}
}