Advertisement
Guest User

Untitled

a guest
Dec 30th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.34 KB | None | 0 0
  1.             while(validLogin == false) {
  2.                 if (messageIn.toUpperCase().startsWith("CREATE")) {
  3.                     FileWriter loginWriter = new FileWriter("LoginDetails.txt", true);
  4.                    
  5.                    
  6.                     dataOut.writeUTF("Please enter a Username: ");
  7.                     username = dataIn.readUTF();
  8.                    
  9.                     dataOut.writeUTF("Please enter a Password: ");
  10.                     password = dataIn.readUTF();
  11.                    
  12.                     createBuffer.mark(10000);
  13.                     while((currentLine = createBuffer.readLine()) != null) {
  14.                         String[] subStrings = currentLine.split(":");
  15.                         String usernameSub = subStrings[0];
  16.                         String passwordSub = subStrings[1];
  17.                                            
  18.                         if (username.equals(subStrings[0])) {
  19.                             dataOut.writeUTF("Login Already Exists, Try Logging In...");
  20.                             username = dataIn.readUTF();
  21.                            
  22.                         }
  23.                         else {
  24.                             if(username != null || username != " ") {
  25.                                 loginWriter.write(username + ":" + password + "\r\n");
  26.                                 dataOut.writeUTF("Login Created, Logging in now...");
  27.                                 loginWriter.close();
  28.                                 validLogin = true;
  29.                                 break;
  30.                         }
  31.                     }
  32.                     createBuffer.reset();
  33.                    
  34.                     if (validLogin == false) {
  35.                         dataOut.writeUTF("Login Failed");
  36.                         }                      
  37.                     }
  38.                 }
  39.                 createBuffer.close();
  40.                
  41.                 if (messageIn.toUpperCase().startsWith("LOGIN")){
  42.                     BufferedReader loginBuffer = new BufferedReader(new FileReader("LoginDetails.txt"));
  43.                    
  44.                     dataOut.writeUTF("Username: ");
  45.                     username = dataIn.readUTF();
  46.                    
  47.                     pattern = Pattern.compile(emailRegex);
  48.                     matcher = pattern.matcher(username);
  49.                     if(matcher.matches() == true){
  50.                        
  51.                         dataOut.writeUTF("Password: ");
  52.                         password = dataIn.readUTF();
  53.                        
  54.                         loginBuffer.mark(10000);
  55.                        
  56.                         while((currentLine = loginBuffer.readLine()) != null) {
  57.                             String[] subStrings = currentLine.split(":");
  58.                             String usernameSub = subStrings[0];
  59.                             String passwordSub = subStrings[1];
  60.                                                
  61.                             if (username.equals(subStrings[0]) && password.equals(subStrings[1])) {
  62.                                 dataOut.writeUTF("Valid Login, Logging In...");
  63.                                 validLogin = true;
  64.                                 retrieving = true;
  65.                                 break;
  66.                             }                  
  67.                         }
  68.                         loginBuffer.reset();   
  69.                        
  70.                         if(validLogin == false) {
  71.                             dataOut.writeUTF("Login Failed");
  72.                         }
  73.                         loginBuffer.close();
  74.                     }
  75.                     else {
  76.                         dataOut.writeUTF("Error in Logging In, Try Again");
  77.                         messageIn = dataIn.readUTF();
  78.                     }                  
  79.                 }
  80.             }
  81.            
  82.             while(retrieving == true) {
  83.                 BufferedReader msgReader = new BufferedReader(new FileReader("SMTPMsgs.txt"));
  84.                 StringBuffer sb = new StringBuffer();
  85.                
  86.                 while(true) {
  87.                     String line = msgReader.readLine();
  88.                     if (line == null) {
  89.                         break;
  90.                     }
  91.                     sb.append(line).append("\n");
  92.                 }
  93.                
  94.                 String[] messages = sb.toString().split("------END OF MESSAGE------");
  95.                
  96.                 for (String message : messages) {
  97.                     message = message.trim();
  98.                     //message = individual message from file
  99.                     String[] data = message.split("\n");
  100.                     String sender = data[1];
  101.                     sender.replace("FROM: ", "");
  102.                    
  103.                     if (username.equals(sender)) {
  104.                         for (String d : data) {
  105.                             dataOut.writeUTF(d);
  106.                         }
  107.                         dataOut.writeUTF("\r\n");
  108.                     }
  109.                     else {
  110.                         break;
  111.                     }
  112.                 }
  113.                 retrieving = false;
  114.                 msgReader.close();
  115.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement