Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package luke.idk;
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Random;
- import javax.swing.JOptionPane;
- /**
- *
- * @author Luke
- * @version 1.00
- * Details: Creates an account choosing a random username and
- * password and stores details into a txt file for later use.
- *
- */
- public class AccountCreator {
- /**
- * Account log in details
- */
- private static String username = "";
- private static String password = "";
- /**
- * Number of accounts to make
- */
- private static String selection = JOptionPane.showInputDialog("How many accounts would you like created?");
- private static int amount = Integer.valueOf(selection);
- /**
- * Alphabet for assigning characters to the log in details
- */
- private static char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
- /**
- * Array List for phrases to spam
- */
- private static String[] phrases = {"Your server is shit!", "CancerScape!", "Go fuck yourselves!", "Je moeder heeft kanker"};
- private static List<String> message = Arrays.asList(phrases);
- /**
- * Main method for executing the programme
- */
- public static void main(String[] args) throws IOException {
- int count = 0;
- for (int i = 0; i < amount; i++) {
- createUser(5);
- createPassword(5);
- login(username, password);
- logout();
- logDetails(username, password);
- System.out.println("Accounts created: " + ++count);
- System.out.println("----------------------------------------------------------------");
- username = "";
- password = "";
- }
- }
- /**
- * False login method for testing purposes
- */
- private static void login(String username, String password) {
- System.out.println("Username: " + username + " - " + "Password: " + password);
- System.out.println("Message sent: " + message.get(new Random().nextInt(message.size())));
- }
- /**
- * False log out method for testing purposes
- */
- private static void logout() {
- System.out.println("Logged out of account: " + username);
- }
- /**
- * Method for creating the username
- */
- private static void createUser(int length) {
- for (int i = 0; i < length; i++) {
- username += alphabet[new Random().nextInt(alphabet.length - 1)];
- }
- }
- /**
- * Method for creating the password
- */
- private static void createPassword(int length) {
- for (int i = 0; i < length; i++) {
- password += alphabet[new Random().nextInt(alphabet.length - 1)];
- }
- }
- /**
- * Method for writing account details to txt file.
- */
- private static void logDetails(String username, String password) throws IOException {
- String details = username + " " + password;
- System.out.println("Logging details: " + details);
- BufferedWriter fw2 = new BufferedWriter(new FileWriter(("accounts.txt"), true));
- fw2.write(details);
- fw2.newLine();
- fw2.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement