Advertisement
Guest User

Account Creator

a guest
Mar 31st, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.90 KB | None | 0 0
  1. package luke.idk;
  2.  
  3. import java.io.BufferedWriter;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.util.Arrays;
  7. import java.util.List;
  8. import java.util.Random;
  9.  
  10. import javax.swing.JOptionPane;
  11.  
  12. /**
  13.  *
  14.  * @author Luke
  15.  * @version 1.00
  16.  * Details: Creates an account choosing a random username and
  17.  *          password and stores details into a txt file for later use.
  18.  *
  19.  */
  20.  
  21. public class AccountCreator {
  22.  
  23.     /**
  24.      * Account log in details
  25.      */
  26.     private static String username = "";
  27.     private static String password = "";
  28.    
  29.     /**
  30.      * Number of accounts to make
  31.      */
  32.     private static String selection = JOptionPane.showInputDialog("How many accounts would you like created?");
  33.     private static int amount = Integer.valueOf(selection);
  34.  
  35.     /**
  36.      * Alphabet for assigning characters to the log in details
  37.      */
  38.     private static char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
  39.    
  40.     /**
  41.      * Array List for phrases to spam
  42.      */
  43.     private static String[] phrases = {"Your server is shit!", "CancerScape!", "Go fuck yourselves!", "Je moeder heeft kanker"};
  44.     private static List<String> message = Arrays.asList(phrases);
  45.    
  46.     /**
  47.      * Main method for executing the programme
  48.      */
  49.     public static void main(String[] args) throws IOException {
  50.         int count = 0;
  51.         for (int i = 0; i < amount; i++) {
  52.             createUser(5);
  53.             createPassword(5);
  54.             login(username, password);
  55.             logout();
  56.             logDetails(username, password);
  57.             System.out.println("Accounts created: " + ++count);
  58.             System.out.println("----------------------------------------------------------------");
  59.             username = "";
  60.             password = "";
  61.         }
  62.     }
  63.  
  64.     /**
  65.      * False login method for testing purposes
  66.      */
  67.     private static void login(String username, String password) {
  68.         System.out.println("Username: " + username + " - " + "Password: " + password);
  69.         System.out.println("Message sent: " + message.get(new Random().nextInt(message.size())));
  70.     }
  71.    
  72.     /**
  73.      * False log out method for testing purposes
  74.      */
  75.     private static void logout() {
  76.         System.out.println("Logged out of account: " + username);
  77.     }
  78.  
  79.     /**
  80.      * Method for creating the username
  81.      */
  82.     private static void createUser(int length) {
  83.         for (int i = 0; i < length; i++) {
  84.             username += alphabet[new Random().nextInt(alphabet.length - 1)];
  85.         }
  86.     }
  87.  
  88.     /**
  89.      * Method for creating the password
  90.      */
  91.     private static void createPassword(int length) {
  92.         for (int i = 0; i < length; i++) {
  93.             password += alphabet[new Random().nextInt(alphabet.length - 1)];
  94.         }
  95.     }
  96.    
  97.     /**
  98.      * Method for writing account details to txt file.
  99.      */
  100.     private static void logDetails(String username, String password) throws IOException {
  101.         String details = username + " " + password;
  102.         System.out.println("Logging details: " + details);
  103.         BufferedWriter fw2 = new BufferedWriter(new FileWriter(("accounts.txt"), true));
  104.         fw2.write(details);
  105.         fw2.newLine();
  106.         fw2.close();
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement