From 398bd4c105230fb4b9d894cf58a6100838e3d3aa Mon Sep 17 00:00:00 2001 From: navcs Date: Mon, 14 Nov 2016 00:32:29 +0700 Subject: [PATCH] First commit --- build.xml | 73 + build/classes/.netbeans_automatic_build | 0 build/classes/.netbeans_update_resources | 0 .../Authentication$Credential.class | Bin 0 -> 985 bytes .../authentication/Authentication.class | Bin 0 -> 6638 bytes build/classes/resources/admin.txt | 3 + build/classes/resources/credentials.txt | 6 + build/classes/resources/veterinarian.txt | 3 + build/classes/resources/zookeeper.txt | 3 + manifest.mf | 3 + nbproject/build-impl.xml | 1419 +++++++++++++++++ nbproject/genfiles.properties | 8 + nbproject/private/config.properties | 0 nbproject/private/private.properties | 6 + nbproject/private/private.xml | 9 + nbproject/project.properties | 76 + nbproject/project.xml | 15 + resources/Veterinarian.txt | 3 + resources/admin.txt | 3 + resources/credentials.txt | 6 + resources/zookeeper.txt | 3 + src/authentication/Authentication.java | 235 +++ src/resources/admin.txt | 3 + src/resources/credentials.txt | 6 + src/resources/veterinarian.txt | 3 + src/resources/zookeeper.txt | 3 + 26 files changed, 1889 insertions(+) create mode 100644 build.xml create mode 100644 build/classes/.netbeans_automatic_build create mode 100644 build/classes/.netbeans_update_resources create mode 100644 build/classes/authentication/Authentication$Credential.class create mode 100644 build/classes/authentication/Authentication.class create mode 100644 build/classes/resources/admin.txt create mode 100644 build/classes/resources/credentials.txt create mode 100644 build/classes/resources/veterinarian.txt create mode 100644 build/classes/resources/zookeeper.txt create mode 100644 manifest.mf create mode 100644 nbproject/build-impl.xml create mode 100644 nbproject/genfiles.properties create mode 100644 nbproject/private/config.properties create mode 100644 nbproject/private/private.properties create mode 100644 nbproject/private/private.xml create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 resources/Veterinarian.txt create mode 100644 resources/admin.txt create mode 100644 resources/credentials.txt create mode 100644 resources/zookeeper.txt create mode 100644 src/authentication/Authentication.java create mode 100644 src/resources/admin.txt create mode 100644 src/resources/credentials.txt create mode 100644 src/resources/veterinarian.txt create mode 100644 src/resources/zookeeper.txt diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..91ebdf2 --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project Authentication. + + + diff --git a/build/classes/.netbeans_automatic_build b/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/build/classes/.netbeans_update_resources b/build/classes/.netbeans_update_resources new file mode 100644 index 0000000..e69de29 diff --git a/build/classes/authentication/Authentication$Credential.class b/build/classes/authentication/Authentication$Credential.class new file mode 100644 index 0000000000000000000000000000000000000000..37625800421d154dbc86707673b974f50e682770 GIT binary patch literal 985 zcmbVK%Wl&^6g}fOapD>XDX$a?1p-aYBLS5as1k~Vga~C()cwR6wNts{YV6Q1`6Q5t zkXY~m`~y3lKY_S++Ni2pp@_|W%{}LyJ2PMYeEJMv8H+VkFwf>Hn`ex|RDS{-cUO&VEA8o_OUE}B@b-vhLivCx zC&@#XtYsscsArnjn>{M)KEFtW2(<_yn<|@AxD{arwE(vT+SBeOP(OU%SA#8;6au9- z-}d}JIj}$DY=OC z`1L9-;NpRr4tee`#~)C7M}Y?(Tye#(Zb-D>fJ;1tz|9lE-gMx(6TxB%Fe$t2^j*O@ N@*%0J;09es_!kc3$`b$p literal 0 HcmV?d00001 diff --git a/build/classes/authentication/Authentication.class b/build/classes/authentication/Authentication.class new file mode 100644 index 0000000000000000000000000000000000000000..25baa817bacdab5dd544c857df01208f87e8a388 GIT binary patch literal 6638 zcmb7I349dSdH=t?W;7ZEtPmi9%wl6BRwput5m@FDAftmI43$aJ468v}d$p_V&KhLX z#EG5zzHAfcaBL?^Vz&ljRyf4QsU6}RZIZ@K)8=S;r)S!vO=35(^8aQ=+Fhg&XMewW z^N#O*-}nCC^=7~N(&wK7uuk;IHvFI=(0G@9X%1h9BzqTiO02 z9e=0e??wB6sKh_wpQQO`4gX?bJ$@_{|0=zIljh&$tp8!)Kk;80eq!Li@jnKBik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ey}ziY_AQ6_=NdH+9$EIfUZLmQ(xnT zT}>CUxA`J!q(6bJ9ie8)Kzk;z-kWI=j(xSE3mp-X))z^m9a?j(=8|ecS{u1Afd#$n z)=WT`_l>7%hkm;AL1vdqJ|q5njQZbBpLl~imt_W#-v@9HGnl+T#((TQOYXu#cczlL zCyEadlY3YY?xnR((xM;c{`<-G1LSZ&+mCbgey)Cm?Z?UGqi*{U9&izVCCkE6=D+tb za6;s=0`F(C4>Qan-1|Y!-R1W*QofziUQguj<@`P5A0V#~^Vq%Y5&apvJ?z@Z3%?%B z`!y=v$h&Xjehv2-yV&gJGsWQ7+=O@1TLz)I4@zi)Q)C(N7J=gXrc9hM~Kd& zsNyGdHU5N|@-b%4Q%psV(Y|L${W&J7$5}Vdx@aF|E?>_G`zY<86YGt{?*XE{iuv^u ztOXI)rdGyWmM4pl!-IH;C$6UDA0}Op{I}wh_!KdJ6)7^9aB&}+!F@>n#Gs}UrEMUF zt0hjQqGeU7`HC5B%jZqIS&MP|b<)6c)++H4PTSm(z; zh*vEyE+X!A%8Q2FOf=k45)F6GSmn-=XxLj44b`)vAyO6%FC!TE&y8m=9>%*E9F_`o zb9wQS+ErTK>j{Vy=Qcjkrs!d>jPru#7ys$v&1EcNy`JEe&b?EW*OG70hrdbh{1*NF z+stUs(<0xYO}^{m=GD8yJ_^;WF~yP`MffGO`PJB16n=rq2N*w68y=%g + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..a2b9b1b --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=71850a38 +build.xml.script.CRC32=9f8b6628 +build.xml.stylesheet.CRC32=8064a381@1.79.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=71850a38 +nbproject/build-impl.xml.script.CRC32=c11c7a85 +nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.1.48 diff --git a/nbproject/private/config.properties b/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties new file mode 100644 index 0000000..1038402 --- /dev/null +++ b/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=/home/navcs/.netbeans/8.1/build.properties diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml new file mode 100644 index 0000000..af8089d --- /dev/null +++ b/nbproject/private/private.xml @@ -0,0 +1,9 @@ + + + + + + file:/home/navcs/outsourcing/Authentication/src/authentication/Authentication.java + + + diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..9cd33b0 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,76 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=Authentication +application.vendor=navcs +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Authentication.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=authentication.Authentication +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..d143896 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + Authentication + + + + + + + + + diff --git a/resources/Veterinarian.txt b/resources/Veterinarian.txt new file mode 100644 index 0000000..6d07611 --- /dev/null +++ b/resources/Veterinarian.txt @@ -0,0 +1,3 @@ +Hello, Veterinarian! + +As veterinarian, you have access to all of the animals' health records. This allows you to view each animal's medical history and current treatments/illnesses (if any), and to maintain a vaccination log. \ No newline at end of file diff --git a/resources/admin.txt b/resources/admin.txt new file mode 100644 index 0000000..2b56b84 --- /dev/null +++ b/resources/admin.txt @@ -0,0 +1,3 @@ +Hello, System Admin! + +As administrator, you have access to the zoo's main computer system. This allows you to monitor users in the system and their roles. \ No newline at end of file diff --git a/resources/credentials.txt b/resources/credentials.txt new file mode 100644 index 0000000..cbf0c18 --- /dev/null +++ b/resources/credentials.txt @@ -0,0 +1,6 @@ +griffin.keyes 108de81c31bf9c622f76876b74e9285f "alphabet soup" zookeeper +rosario.dawson 3e34baa4ee2ff767af8c120a496742b5 "animal doctor" admin +bernie.gorilla a584efafa8f9ea7fe5cf18442f32b07b "secret password" veterinarian +donald.monkey 17b1b7d8a706696ed220bc414f729ad3 "M0nk3y business" zookeeper +jerome.grizzlybear 3adea92111e6307f8f2aae4721e77900 "grizzly1234" veterinarian +bruce.grizzlybear 0d107d09f5bbe40cade3de5c71e9e9b7 "letmein" admin \ No newline at end of file diff --git a/resources/zookeeper.txt b/resources/zookeeper.txt new file mode 100644 index 0000000..31da726 --- /dev/null +++ b/resources/zookeeper.txt @@ -0,0 +1,3 @@ +Hello, Zookeeper! + +As zookeeper, you have access to all of the animals' information and their daily monitoring logs. This allows you to track their feeding habits, habitat conditions, and general welfare. \ No newline at end of file diff --git a/src/authentication/Authentication.java b/src/authentication/Authentication.java new file mode 100644 index 0000000..0a3d77b --- /dev/null +++ b/src/authentication/Authentication.java @@ -0,0 +1,235 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package authentication; + +import java.io.File; +import java.io.IOException; +import static java.lang.System.exit; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Scanner; + +/** + * The Authentication class provices module Authentication System + */ +public class Authentication { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + mainMenu(); + } + + private ArrayList credentials; // list object Credential + private String username; // username log in to System + private String password; // password log in to System + private String role; // role of user log in to System + + /** + * Class constructor and run flow of module. + * @param fileName the name of file stored all credentials. + */ + public Authentication(String fileName) { + credentials = new ArrayList(); + username = ""; + password = ""; + setCredentials(getFile(fileName)); + loginScreen(); + int limitAuthenFail = 2; + for (int i = 0; i < limitAuthenFail; i++) { + if (authenticate()) { + break; + } else { + System.out.println("Incorrect information. Please try again!"); + loginScreen(); + if (i == (limitAuthenFail - 1)) { + System.out.println("You're wrong too many times allowed. Press to exit !"); + try { + System.in.read(); + System.exit(0); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + } + getDisplayRole(getFile("resources/" + role+".txt")); + logout(); + } + + /** + * This method display main menu of module. + */ + + private static void mainMenu() { + String selection; + Scanner input = new Scanner(System.in); + + // Display menu graphics + System.out.println("============================"); + System.out.println("|WELCOME TO SYSTEM THE ZOO |"); + System.out.println("============================"); + System.out.println("| Options: |"); + System.out.println("| 1. Log in |"); + System.out.println("| 2. Exit |"); + System.out.println("============================"); + System.out.print(" Select option: "); + selection = input.nextLine(); + + // Switch construct + switch (selection) { + case "1": + new Authentication("resources/credentials.txt"); + break; + case "2": + exit(0); + default: + mainMenu(); + break; // This break is not really necessary + } + } + /** + * This method display login and options select action. + */ + private void loginScreen() { + System.out.print("| Username: "); + Scanner input = new Scanner(System.in); + username = input.nextLine(); + System.out.print("| Password: "); + password = input.nextLine(); + } + + /** + * Return true or false. + *

+ * This method always returns immediately, whether or not the username and password had been stored. + * @return true/false + */ + private boolean authenticate() { + for (Authentication.Credential credential : credentials) { + if (username.equals(credential.username)) { + if (encodeMd5(password).equals(credential.passwordMd5)) { + role = credential.role; + return true; + } + } + } + return false; + } + + /** + * Return an File object that can be find in package resources. + * The file name argument must specify an absolute path file. + *

+ * This method always return an File object. + * @param fileName the name of file want to get. + * @return the File object + */ + private File getFile(String fileName) { + //Get file from resources folder + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader.getResource(fileName).getFile()); + + return file; + } + + /** + * This method read file "credentials.txt" and add credential object to a list. + * @param file the File object "credentials.txt" + */ + private void setCredentials(File file) { + try (Scanner scanner = new Scanner(file)) { + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + String[] credentialData = line.split("\t"); + credentials.add(new Authentication.Credential(credentialData[0], + credentialData[1], credentialData[2], credentialData[3])); + } + scanner.close(); + } catch (IOException e) { + e.printStackTrace(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + /** + * Returns a string that can then be encode MD5. + *

+ * This method create an MD5 hash of a String and always returns immediately. + * @param password the string will be encode MD5. + * @return the password was encode MD5 + */ + private String encodeMd5(String password) { + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + md.update(password.getBytes()); + byte[] digest = md.digest(); + StringBuffer sb = new StringBuffer(); + for (byte b : digest) { + sb.append(String.format("%02x", b & 0xff)); + } + return sb.toString(); + } catch (NoSuchAlgorithmException ex) { + ex.printStackTrace(); + return ""; + } + + } + + /** + * This method display content in the role file after successful authentication. + * @param file the File object role of user log in to System + */ + private void getDisplayRole(File file) { + try (Scanner scanner = new Scanner(file)) { + while (scanner.hasNextLine()) { + System.out.println(scanner.nextLine()); + } + scanner.close(); + } catch (IOException e) { + e.printStackTrace(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + /** + * This method display logout screen. + */ + private void logout() { + System.out.print("| Enter 0 to log out: "); + Scanner input = new Scanner(System.in); + switch(input.nextLine()) { + case "0": + mainMenu(); + break; + default: + logout(); + } + } + + /** + * Credential is the inner class for an instance of object credential. + */ + private static class Credential { + + private String username; + private String passwordMd5; + private String password; + private String role; + + public Credential(String username, String passwordMd5, String password, String role) { + this.username = username; + this.passwordMd5 = passwordMd5; + this.password = password; + this.role = role; + } + } +} diff --git a/src/resources/admin.txt b/src/resources/admin.txt new file mode 100644 index 0000000..2b56b84 --- /dev/null +++ b/src/resources/admin.txt @@ -0,0 +1,3 @@ +Hello, System Admin! + +As administrator, you have access to the zoo's main computer system. This allows you to monitor users in the system and their roles. \ No newline at end of file diff --git a/src/resources/credentials.txt b/src/resources/credentials.txt new file mode 100644 index 0000000..cbf0c18 --- /dev/null +++ b/src/resources/credentials.txt @@ -0,0 +1,6 @@ +griffin.keyes 108de81c31bf9c622f76876b74e9285f "alphabet soup" zookeeper +rosario.dawson 3e34baa4ee2ff767af8c120a496742b5 "animal doctor" admin +bernie.gorilla a584efafa8f9ea7fe5cf18442f32b07b "secret password" veterinarian +donald.monkey 17b1b7d8a706696ed220bc414f729ad3 "M0nk3y business" zookeeper +jerome.grizzlybear 3adea92111e6307f8f2aae4721e77900 "grizzly1234" veterinarian +bruce.grizzlybear 0d107d09f5bbe40cade3de5c71e9e9b7 "letmein" admin \ No newline at end of file diff --git a/src/resources/veterinarian.txt b/src/resources/veterinarian.txt new file mode 100644 index 0000000..6d07611 --- /dev/null +++ b/src/resources/veterinarian.txt @@ -0,0 +1,3 @@ +Hello, Veterinarian! + +As veterinarian, you have access to all of the animals' health records. This allows you to view each animal's medical history and current treatments/illnesses (if any), and to maintain a vaccination log. \ No newline at end of file diff --git a/src/resources/zookeeper.txt b/src/resources/zookeeper.txt new file mode 100644 index 0000000..31da726 --- /dev/null +++ b/src/resources/zookeeper.txt @@ -0,0 +1,3 @@ +Hello, Zookeeper! + +As zookeeper, you have access to all of the animals' information and their daily monitoring logs. This allows you to track their feeding habits, habitat conditions, and general welfare. \ No newline at end of file