Guest User

Untitled

a guest
Apr 20th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.24 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package clientcoursework2;
  6.  
  7. import java.io.BufferedReader;
  8. import java.io.IOException;
  9. import java.io.InputStreamReader;
  10. import java.io.PrintWriter;
  11. import java.net.Socket;
  12. import java.net.UnknownHostException;
  13. import java.util.logging.Level;
  14. import java.util.logging.Logger;
  15. import javax.swing.JOptionPane;
  16. import javax.swing.JTextField;
  17.  
  18. /**
  19.  *
  20.  * @author User
  21.  */
  22. public class Login {
  23.    
  24.         public int port = 1234;
  25.     //public String ip = null;
  26.     public Socket login = null;
  27.     public PrintWriter outStream = null;
  28.     private BufferedReader inStream = null;
  29.     private boolean ON = false;
  30.     public String authorize = null;
  31.    
  32.      public boolean Loginn(String UserName, String PassWord, String IP) throws UnknownHostException, IOException {
  33.                    
  34.        
  35.          
  36.                 login = new Socket(IP, port);
  37.                
  38.                 //inStream = new BufferedReader(new InputStreamReader(client.getInputStream()));
  39.                 //while (!inStream.ready()) {}
  40.                 //System.out.println(inStream.readLine()); // Read one line and output it
  41.                 outStream = new PrintWriter(login.getOutputStream(), true);          
  42.                 outStream.println(UserName + " " + PassWord);
  43.                 //outStream.close();
  44.                
  45.                 inStream = new BufferedReader(new InputStreamReader(login.getInputStream()));
  46.                 authorize = inStream.readLine();
  47.                 System.out.println(authorize); // Read one line and output it
  48.                 //inStream.close();
  49.                
  50.                
  51.                 if (authorize.equals("logincomplete"))
  52.                 {
  53.                     JOptionPane.showMessageDialog(null,"Welcome: " + UserName);
  54.                     login.close();
  55.                     return true;
  56.                 }
  57.                 else
  58.                 {
  59.                     JOptionPane.showMessageDialog(null,"Logged Failed! User '" + UserName + "' Does Not Exist!");
  60.                     return false;
  61.                    
  62.                 }
  63.                
  64.                
  65.            
  66.         }
  67.  
  68.    
  69.     }
Advertisement
Add Comment
Please, Sign In to add comment