Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while(validLogin == false) {
- if (messageIn.toUpperCase().startsWith("CREATE")) {
- FileWriter loginWriter = new FileWriter("LoginDetails.txt", true);
- dataOut.writeUTF("Please enter a Username: ");
- username = dataIn.readUTF();
- dataOut.writeUTF("Please enter a Password: ");
- password = dataIn.readUTF();
- createBuffer.mark(10000);
- while((currentLine = createBuffer.readLine()) != null) {
- String[] subStrings = currentLine.split(":");
- String usernameSub = subStrings[0];
- String passwordSub = subStrings[1];
- if (username.equals(subStrings[0])) {
- dataOut.writeUTF("Login Already Exists, Try Logging In...");
- username = dataIn.readUTF();
- }
- else {
- if(username != null || username != " ") {
- loginWriter.write(username + ":" + password + "\r\n");
- dataOut.writeUTF("Login Created, Logging in now...");
- loginWriter.close();
- validLogin = true;
- break;
- }
- }
- createBuffer.reset();
- if (validLogin == false) {
- dataOut.writeUTF("Login Failed");
- }
- }
- }
- createBuffer.close();
- if (messageIn.toUpperCase().startsWith("LOGIN")){
- BufferedReader loginBuffer = new BufferedReader(new FileReader("LoginDetails.txt"));
- dataOut.writeUTF("Username: ");
- username = dataIn.readUTF();
- pattern = Pattern.compile(emailRegex);
- matcher = pattern.matcher(username);
- if(matcher.matches() == true){
- dataOut.writeUTF("Password: ");
- password = dataIn.readUTF();
- loginBuffer.mark(10000);
- while((currentLine = loginBuffer.readLine()) != null) {
- String[] subStrings = currentLine.split(":");
- String usernameSub = subStrings[0];
- String passwordSub = subStrings[1];
- if (username.equals(subStrings[0]) && password.equals(subStrings[1])) {
- dataOut.writeUTF("Valid Login, Logging In...");
- validLogin = true;
- retrieving = true;
- break;
- }
- }
- loginBuffer.reset();
- if(validLogin == false) {
- dataOut.writeUTF("Login Failed");
- }
- loginBuffer.close();
- }
- else {
- dataOut.writeUTF("Error in Logging In, Try Again");
- messageIn = dataIn.readUTF();
- }
- }
- }
- while(retrieving == true) {
- BufferedReader msgReader = new BufferedReader(new FileReader("SMTPMsgs.txt"));
- StringBuffer sb = new StringBuffer();
- while(true) {
- String line = msgReader.readLine();
- if (line == null) {
- break;
- }
- sb.append(line).append("\n");
- }
- String[] messages = sb.toString().split("------END OF MESSAGE------");
- for (String message : messages) {
- message = message.trim();
- //message = individual message from file
- String[] data = message.split("\n");
- String sender = data[1];
- sender.replace("FROM: ", "");
- if (username.equals(sender)) {
- for (String d : data) {
- dataOut.writeUTF(d);
- }
- dataOut.writeUTF("\r\n");
- }
- else {
- break;
- }
- }
- retrieving = false;
- msgReader.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement