Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.endless.util;
- import halloa.HalloaDB;
- import java.io.*;
- import java.util.Scanner;
- import com.endless.account.Account;
- public class MakeAccount {
- public static void main(String[] args) throws Exception {
- System.out.println("Input username:");
- Scanner scan = new Scanner(System.in);
- String inputUser = scan.nextLine();
- System.out.println("Input password:");
- Scanner scan2 = new Scanner(System.in);
- String inputPass = scan2.nextLine();
- //String user = args[0].toLowerCase(); // <-- this... needs to be all lowercase
- //String password = args[1];
- String user = inputUser.toLowerCase();;
- String password = inputPass;
- HalloaDB accounts = new HalloaDB(new File("./data/accounts"));
- Account acc = new Account();
- acc.setUsername(user);
- acc.setPassword(password);
- acc.setRights(0);
- accounts.put(user, acc);
- //File accReg = new File(".data/accounts/"+user+".txt")
- File file = new File("data/accounts/"+user+".txt");
- if(file.exists()) {
- System.out.println("Username already used.");
- return;
- } else {
- BufferedWriter buffered = new BufferedWriter(new FileWriter(file));
- buffered.write(user);
- buffered.newLine();
- buffered.write(password);
- buffered.newLine();
- buffered.write(acc.getRights());
- //XXX Add position etc
- buffered.close();
- }
- System.out.println(" ");
- System.out.println("New account created.");
- System.out.println("Username: "+user);
- System.out.println("Password: "+password);
- }
- public static String formatName(String name){
- char[] c = name.toLowerCase().trim().toCharArray();
- if (c.length > 0) {
- c[0] = Character.toUpperCase(c[0]);
- }
- for (int i = 0; i < c.length; i++) {
- if (c[i] == ' ') {
- c[i + 1] = Character.toUpperCase(c[i + 1]);
- }
- }
- return new String(c);
- }
- }
Add Comment
Please, Sign In to add comment