Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


super specific login program(ugly draft code) filter_list
Author
Message
super specific login program(ugly draft code) #1
hey guys! here's a little program I made when I was bored in computer science, the code is SUPER ugly because its just a draft for a different program I'm going to make that will implement it, here it is:

Code:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.UUID;

/**
* This program demonstrates how to generate a secret-key object for
* HMAC-MD5, and initialize an HMAC-MD5 object with it.
*/

public class initMac {
static boolean checked = false;
static String bool = "";
static String reg = "";
    public static void main(String[] args) throws Exception {
  
    UUID a = UUID.randomUUID();
      
       File f = new File("serial.txt");
       File r = new File("acc.txt");
       File c = new File("checked.txt");
       File b = new File("users.txt");
       File u = new File("Props.txt");
       if(!b.exists()){
      b.createNewFile();
       }
       if(!r.exists()){
      r.createNewFile();
       }
       if(!c.exists()){
      c.createNewFile();
       }
       if(!f.exists()){
       System.out.println(a + " is your serial number");
       f.createNewFile();
       System.out.println("File created");
       }
       if(!u.exists()){
      u.createNewFile();
       }
       if (c.length() == 0){
           try{
           // Create file
           FileWriter fstream = new FileWriter(c);
               BufferedWriter out = new BufferedWriter(fstream);
           out.write("false");
           //out.newLine();
           
           //Close the output stream
           out.close();
           }catch (Exception e){//Catch exception if any
           System.err.println("Error: " + e.getMessage() + " writing c: False");
           }
           }
       if (u.length() == 0){
           try{
           // Create file
           FileWriter fstream = new FileWriter(u);
               BufferedWriter out = new BufferedWriter(fstream);
           out.write(System.getProperties() + "");
           //out.newLine();
           
           //Close the output stream
           out.close();
           }catch (Exception e){//Catch exception if any
           System.err.println("Error: " + e.getMessage() + " Writing u");
           }
           }
       if (f.length() == 0){
       try{
       // Create file
       FileWriter fstream = new FileWriter(f);
           BufferedWriter out = new BufferedWriter(fstream);
       out.write(a.toString());
       out.newLine();
       System.out.println(a + " is your serial number");
       //Close the output stream
       out.close();
       }catch (Exception e){//Catch exception if any
       System.err.println("Error: " + e.getMessage() + " Writing f");
       }
       }
       String properties = "";
       if (u.length() == 0){
           try{
           // Create file
           FileWriter fstream = new FileWriter(u);
               BufferedWriter out = new BufferedWriter(fstream);
           out.write(System.getProperties().toString());
           out.newLine();
           //System.out.println(System.getProperties() + " added to file " + u.getName());
           //Close the output stream
           out.close();
           }catch (Exception e){//Catch exception if any
           System.err.println("Error: " + e.getMessage() + " Writing u");
           }
           }
       try{
// Open the file that is the first
// command line parameter
FileInputStream fs = new FileInputStream(u);
// Get the object of DataInputStream
DataInputStream in1 = new DataInputStream(fs);
       BufferedReader br1 = new BufferedReader(new InputStreamReader(in1));
String str;
//Read File Line By Line
String[] props = new String[(int) u.length()];
int i = 0;
while ((str = br1.readLine()) != null) {
properties = str;
}
if(!System.getProperties().toString().contains(properties)){
System.out.println("You are using an illigal version of this program. props");
System.out.println("");
System.out.println("");
System.out.println(properties);
System.out.println("");
System.out.println(System.getProperties());
System.exit(0);
}
try{
// Open the file that is the first
// command line parameter
FileInputStream fss = new FileInputStream(c);
// Get the object of DataInputStream
DataInputStream in2 = new DataInputStream(fss);
       BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));
String booel = "";
//Read File Line By Line
while ((booel = br2.readLine()) != null) {
bool = booel;
}
}catch(Exception e){
System.err.println("Could not read file checked");
}    
if(bool.contains("false")){
      Scanner scan = new Scanner(System.in);
      System.out.print("Enter Serial Number: ");
      String serial = scan.next();
      
      try{
    // Open the file that is the first
    // command line parameter
    FileInputStream fstream = new FileInputStream(f);
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
           BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    //Read File Line By Line
    String[] ids = new String[(int) f.length()];
    int y = 0;
    while ((strLine = br.readLine()) != null) {
    ids[i] = strLine;
    y++;
    }
  
    if(ids.length > 38 || ids.length < 38){
    System.out.println("You are using an illigal copy of this program. serial");
    System.exit(0);
    }else if (ids.length == 38){
    String s = serial;
    for(int j = 0; j < ids.length; j++){
    if(ids[j].equals(s)){
    break;
    }
    else{
    System.out.println("Access Denied");
    System.exit(0);
    }
    }
    }
    //Close the input stream
    in.close();
    }catch (Exception e){//Catch exception if any
    System.err.println("Error: " +  " Reading f");
  
    e.printStackTrace();
    }
      
      checked = true;
      
               try{
               // Create file
               FileWriter fstream = new FileWriter(c);
                   BufferedWriter out = new BufferedWriter(fstream);
               out.write("true");
               //out.newLine();
               
               //Close the output stream
               out.close();
               }catch (Exception e){//Catch exception if any
               System.err.println("Error: " + e.getMessage() + " Writing c: True");
               
               }
              
}//end of if not checked
try{
// Open the file that is the first
// command line parameter
FileInputStream fss = new FileInputStream(c);
// Get the object of DataInputStream
DataInputStream in2 = new DataInputStream(fss);
       BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));
String booel = "";
//Read File Line By Line
while ((booel = br2.readLine()) != null) {
bool = booel;
}
}catch(Exception e){
System.err.println("Could not read file checked");
}    
try{
// Open the file that is the first
// command line parameter
FileInputStream fsss = new FileInputStream(r);
// Get the object of DataInputStream
DataInputStream in3 = new DataInputStream(fsss);
       BufferedReader br3 = new BufferedReader(new InputStreamReader(in3));
String regs = "";
//Read File Line By Line
while ((regs = br3.readLine()) != null) {
reg = regs;
}
}catch(Exception e){
System.err.println("Could not read file checked");
}
String boole = bool;
if(boole.contains("true")){
if(b.length() == 0){
Scanner scan = new Scanner(System.in);
System.out.print("Enter desired user: ");
String user = scan.next();
try{
          // Create file
          FileWriter fstream = new FileWriter(b);
                  BufferedWriter out = new BufferedWriter(fstream);
          out.write(user);
          out.newLine();
        
          //Close the output stream
          out.close();
          }catch (Exception e){//Catch exception if any
          System.err.println("Error: " + e.getMessage() +  " Writing b");
          }
login();
}else if (b.length() > 0){
login();
}
}else{
System.err.println("SOMETHING WENT WRONG");
System.exit(0);
}
    }catch(Exception e){
    System.err.println("MAJOR ERROR");
    e.printStackTrace();
    }
      
}
private static void login() {
File f = new File("users.txt");
String[] usernames = new String[(int) f.length()];
try{
// Open the file that is the first
// command line parameter
FileInputStream fsss = new FileInputStream(f);
// Get the object of DataInputStream
DataInputStream in3 = new DataInputStream(fsss);
       BufferedReader br3 = new BufferedReader(new InputStreamReader(in3));
String users = "";
//Read File Line By Line
int i = 0;
while ((users = br3.readLine()) != null) {
usernames[i] = users;
i++;
}
Scanner scan = new Scanner(System.in);
System.out.print("Enter username: ");
String user = scan.next();
if(Arrays.toString(usernames).contains(user)){
System.out.println("Access granted! you have successfully entered!!");
}else{
System.err.println("Access denied: username is incorrect, will try again in 3 seconds");
Thread.sleep(3000);
login();
}
}catch(Exception e){
System.err.println("Could not read file users");
e.printStackTrace();
}
}
}

Reply







Users browsing this thread: 1 Guest(s)