Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.net.Socket;
- import java.nio.charset.StandardCharsets;
- import java.util.List;
- import clientInput.CommandBase;
- import colors.ColorClass;
- import database.ManageUsers;
- import encryption.Encrypt;
- public class CncThread implements Runnable{
- private final Socket socket;
- private PrintWriter writer;
- private BufferedReader reader;
- private boolean running;
- private final List<PrintWriter> otherUsers;
- private String username;
- private String password;
- ColorClass cc = new ColorClass();
- ManageUsers mu = new ManageUsers();
- public CncThread(Socket socket, List<PrintWriter> otherUsers) {
- this.socket = socket;
- this.otherUsers = otherUsers;
- try {
- writer = new PrintWriter(socket.getOutputStream());
- reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- running = true;
- this.otherUsers.add(writer);
- } catch(IOException ioe) {
- }
- }
- @Override
- public void run() {
- writer.print("Username: ");
- writer.flush();
- username = this.getText();
- username = username.trim();
- CommandBase cb = new CommandBase(username);
- if(!username.isEmpty()) {
- do {
- writer.print("Password: ");
- writer.flush();
- password = this.getText();
- password = password.trim();
- if(password.length() < 6) {
- writer.println("Password must at least have 6 letters!");
- }
- }while(password.length() < 6);
- } else {
- System.exit(0);
- }
- //Continue here and fix the db nigger
- if(mu.hasUserAccess(username)) {
- if(mu.isUserExpired()) {
- writer.print("User expired!");
- System.exit(0);
- } else {
- Encrypt en = new Encrypt();
- password = en.encryption(password); //Write encrypted password to the getPass var
- //Check if the username already exist in the database
- System.out.print(password);
- ManageUsers muT = new ManageUsers(username, password);
- muT.userManager();
- }
- } else {
- writer.print("Your access was revoked!");
- System.exit(0);
- }
- while(running) {
- String message = this.getText();
- if(message == null) {
- running = false;
- } else {
- }
- }
- this.otherUsers.remove(otherUsers.indexOf(writer));
- this.closeCloseable(reader);
- this.closeCloseable(writer);
- this.closeCloseable(socket);
- }
- private void closeCloseable(AutoCloseable closeable) {
- if(closeable != null) {
- try {
- closeable.close();
- } catch(Exception e) {
- }
- }
- }
- private String getText() {
- try {
- return reader.readLine();
- } catch(IOException ioe) {
- }
- return null;
- }
- }
Add Comment
Please, Sign In to add comment