Advertisement
Guest User

Account Creator

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