Guest User

Untitled

a guest
May 12th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. package com.endless.util;
  2.  
  3. import halloa.HalloaDB;
  4.  
  5. import java.io.*;
  6. import java.util.Scanner;
  7.  
  8. import com.endless.account.Account;
  9.  
  10. public class MakeAccount {
  11.  
  12. public static void main(String[] args) throws Exception {
  13. System.out.println("Input username:");
  14. Scanner scan = new Scanner(System.in);
  15. String inputUser = scan.nextLine();
  16. System.out.println("Input password:");
  17. Scanner scan2 = new Scanner(System.in);
  18. String inputPass = scan2.nextLine();
  19.  
  20. //String user = args[0].toLowerCase(); // <-- this... needs to be all lowercase
  21. //String password = args[1];
  22.  
  23. String user = inputUser.toLowerCase();;
  24. String password = inputPass;
  25.  
  26. HalloaDB accounts = new HalloaDB(new File("./data/accounts"));
  27. Account acc = new Account();
  28. acc.setUsername(user);
  29. acc.setPassword(password);
  30. acc.setRights(0);
  31. accounts.put(user, acc);
  32.  
  33. //File accReg = new File(".data/accounts/"+user+".txt")
  34. File file = new File("data/accounts/"+user+".txt");
  35. if(file.exists()) {
  36. System.out.println("Username already used.");
  37. return;
  38. } else {
  39. BufferedWriter buffered = new BufferedWriter(new FileWriter(file));
  40. buffered.write(user);
  41. buffered.newLine();
  42. buffered.write(password);
  43. buffered.newLine();
  44. buffered.write(acc.getRights());
  45. //XXX Add position etc
  46. buffered.close();
  47. }
  48.  
  49. System.out.println(" ");
  50. System.out.println("New account created.");
  51. System.out.println("Username: "+user);
  52. System.out.println("Password: "+password);
  53. }
  54.  
  55. public static String formatName(String name){
  56. char[] c = name.toLowerCase().trim().toCharArray();
  57. if (c.length > 0) {
  58. c[0] = Character.toUpperCase(c[0]);
  59. }
  60. for (int i = 0; i < c.length; i++) {
  61. if (c[i] == ' ') {
  62. c[i + 1] = Character.toUpperCase(c[i + 1]);
  63. }
  64. }
  65. return new String(c);
  66. }
  67. }
Add Comment
Please, Sign In to add comment