From b9540f162fb83c8037ec1ce9fc04648495b3d17c Mon Sep 17 00:00:00 2001 From: Deathsbreed Date: Sat, 15 Nov 2014 23:47:21 -0600 Subject: [PATCH] Admin password is now stored. --- src/consolechat/client/Client.java | 2 +- src/consolechat/server/Server.java | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/consolechat/client/Client.java b/src/consolechat/client/Client.java index f6f1eef..54a0d9c 100644 --- a/src/consolechat/client/Client.java +++ b/src/consolechat/client/Client.java @@ -83,7 +83,7 @@ public class Client implements Runnable { private void start() throws IOException { console = new BufferedReader(new InputStreamReader(System.in)); streamOut = new DataOutputStream(socket.getOutputStream()); - + if(thread == null) { cThread = new ClientThread(this, socket); thread = new Thread(this); diff --git a/src/consolechat/server/Server.java b/src/consolechat/server/Server.java index f199cbe..9b8b9a1 100644 --- a/src/consolechat/server/Server.java +++ b/src/consolechat/server/Server.java @@ -45,6 +45,15 @@ public class Server implements Runnable { } catch(IOException e) { System.out.println(e); } + + try { + BufferedReader br = new BufferedReader(new FileReader("adminpasswd.txt")); + try { + passwd = br.readLine(); + } catch(IOException ioe) { + System.out.println("Error reading from adminpassword.txt."); + } + } catch(FileNotFoundException fnfe) { System.out.println("No adminpasswd.txt file."); } } // The run method that will be called every frame @@ -182,5 +191,16 @@ public class Server implements Runnable { public String getPasswd() { return passwd; } // Setter methods - public void setPasswd(String npasswd) { this.passwd = npasswd; } + public void setPasswd(String npasswd) { + this.passwd = npasswd; + try { + PrintWriter writer = new PrintWriter("adminpasswd.txt", "UTF-8"); + writer.println(npasswd); + writer.close(); + } catch(UnsupportedEncodingException uee) { + System.out.println("Error writing new password to adminpasswd.txt"); + } catch(FileNotFoundException fnfe) { + System.out.println("Error writing new password to adminpasswd.txt"); + } + } }