Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package it145finalproject;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import java.util.Scanner;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class IT145FinalProject {
- public static void main(String[] args) {
- Scanner scnr = new Scanner(System.in);
- int loginAttempts = 0;
- String userName;
- String userPass;
- FileInputStream inCredentials = null;
- FileInputStream inAdmin = null;
- FileInputStream inVeterinarian = null;
- FileInputStream inZookeeper = null;
- Scanner inCreds = null;
- Scanner inAd = null;
- Scanner inVet = null;
- Scanner inZoo = null;
- String fileName = "";
- String fileHash = "";
- String filePass = "";
- String fileLevel = "";
- try {
- inCredentials = new FileInputStream("credentials.txt");
- } catch (FileNotFoundException ex) {
- Logger.getLogger(IT145FinalProject.class.getName()).log(Level.SEVERE, null, ex);
- }
- inCreds = new Scanner(inCredentials);
- try {
- inAdmin = new FileInputStream("admin.txt");
- } catch
- (FileNotFoundException ex) {
- Logger.getLogger(IT145FinalProject.class.getName()).log (Level.SEVERE, null, ex);
- }
- inAd = new Scanner(inAdmin);
- try {
- inVeterinarian = new FileInputStream("veterinarian.txt");
- } catch (FileNotFoundException ex) {
- Logger.getLogger(IT145FinalProject.class.getName()).log(Level.SEVERE, null, ex);
- }
- inVet = new Scanner(inVeterinarian);
- try {
- inZookeeper = new FileInputStream("zookeeper.txt");
- } catch (FileNotFoundException ex) {
- Logger.getLogger(IT145FinalProject.class.getName()).log(Level.SEVERE, null, ex);
- }
- inZoo = new Scanner(inZookeeper);
- System.out.println("Enter username: ");
- userName = scnr.next();
- System.out.println("Enter password: ");
- userPass = scnr.next();
- while (loginAttempts < 3) {
- String original = userPass; //Replace "password" with the actual password inputted by the user
- MessageDigest md = null;
- try {
- md = MessageDigest.getInstance("MD5");
- } catch (NoSuchAlgorithmException ex) {
- Logger.getLogger(IT145FinalProject.class.getName()).log(Level.SEVERE, null, ex);
- }
- md.update(original.getBytes());
- byte[] digest = md.digest();
- StringBuffer sb = new StringBuffer();
- for (byte b : digest) {
- sb.append(String.format("%02x", b & 0xff));
- }
- fileName = inCreds.next();
- fileHash = inCreds.next();
- filePass = inCreds.next();
- fileLevel = inCreds.next();
- while (userName.equals(fileName)) {
- while (userPass.equals(filePass)) {
- if (fileLevel.equals("zookeeper")){
- System.out.print(inZoo);
- }
- else if (fileLevel.equals("admin")){
- System.out.print(inAd);
- }
- else if (fileLevel.equals("veterinarian")){
- System.out.print(inVet);
- }
- }
- }
- loginAttempts++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement