Advertisement
Guest User

longAndRegister.java

a guest
Feb 26th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.lang.Object;
  3. import java.lang.Throwable;
  4. import java.lang.Exception;
  5. import java.net.MalformedURLException;
  6. import java.io.BufferedReader;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. import java.io.InputStreamReader;
  10. import java.net.URL;
  11. import java.net.URLConnection;
  12. import java.net.HttpURLConnection;
  13. import javax.swing.JOptionPane;
  14.  
  15. public class loginAndRegister
  16. {
  17.     public static String webdata = "";
  18.     public static String err1 = "Website did not return any data. Please check your internet connection and try again";
  19.  
  20.     public static void main(String[] args) // The main class
  21.     {
  22.         // Testing the website connection variables
  23.         checkconn();
  24.     }
  25.  
  26.     private static void checkconn()
  27.     {
  28.         try
  29.         {
  30.             URL url = new URL("http://example.com/");
  31.             URLConnection con = url.openConnection();
  32.             // Connection being established
  33.             InputStream is = con.getInputStream(); // Creating the data stream
  34.             BufferedReader br = new BufferedReader(new InputStreamReader(is)); // Reading the data from the stream
  35.  
  36.             String line = null;
  37.             while ((line = br.readLine()) != null)
  38.             {
  39.                 webdata = line;
  40.  
  41.                 if (webdata != null)
  42.                 {
  43.                     Scanner scan = new Scanner(System.in);
  44.  
  45.                     String user = scan.nextLine();
  46.                     String pass = scan.nextLine();
  47.                     tryLogin(user, pass);
  48.                 }
  49.                 else
  50.                 {
  51.                     System.out.println(err1);
  52.                 }
  53.             }
  54.         }
  55.         catch (MalformedURLException e)
  56.         {
  57.             System.out.println(e);
  58.         }
  59.         catch (IOException e)
  60.         {
  61.             System.out.println(e);
  62.         }
  63.     }
  64.  
  65.     private static void tryLogin(String username, String password)
  66.     {
  67.         if (username == "root" && password == "password")
  68.         {
  69.             System.out.println("Login");
  70.         }
  71.         else
  72.         {
  73.             System.out.println("Failed");
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement