wm: java

Download patch

ref: 0d5aae7a298bb7b4307721554ba07fb1712b18d8
parent: 1c0f4ee56ccae8da705f3259c1d6376bd989d183
author: mkf <mkf@d510>
date: Sat May 27 03:01:36 EDT 2023

improve security, double check for quit, remove Password for AdminAttrs (security!) make listing better (or worse?)

--- a/Main.java
+++ b/Main.java
@@ -2,7 +2,9 @@
 
 // XXX get rid of *s
 // handle throws
+// make whatever you can final
 
+
 /*
 import java.util.regex.Pattern; // Pattern, Matcher
 import java.util.Matcher; // Scanner, ArrayList
@@ -48,7 +50,7 @@
 	Owner;
 }
 
-enum UserAttr
+enum AdminAttr
 {
 	Username,
 	role,
@@ -55,11 +57,11 @@
 	Reserved,
 	ID,
 	RegTime,
-	Age,
+	// Password,
 	Active;
 }
 
-enum AdminAttr
+enum UserAttr
 {
 	Username,
 	role,
@@ -66,10 +68,12 @@
 	Reserved,
 	ID,
 	RegTime,
-	Password,
+	Age,
 	Active;
 }
 
+
+
 interface Library 
 {
 	/* admin */
@@ -129,7 +133,7 @@
 		void Menu(Admin u);
 		// void Menu(User u);
 
-		/* Gets a String, either console or scanner, just check if it's valid or not */
+		/* Gets a String, either console or scanner, checks if it's valid or not, and encrypt it */
 		String GetUsername();
 		String GetPassword();
 		
@@ -141,7 +145,7 @@
 		/* search foolan menu */
 		// void SearchAdmin();
 		// void SearchUser();
-		// void SearchBook();
+		void SearchBook();
 
 		/* add foolan menu */
 		void AddAdmin();
@@ -401,7 +405,7 @@
 		temp.put(AdminAttr.Reserved, getReserved());
 		temp.put(AdminAttr.ID, Integer.toString(getID()));
 		temp.put(AdminAttr.RegTime, getRegTime().toString());
-		temp.put(AdminAttr.Password, this.Password);
+		/*  temp.put(AdminAttr.Password, this.Password); secrect secrect secrect */
 		temp.put(AdminAttr.Active, Boolean.toString(this.Active));
 
 		return temp;
@@ -990,7 +994,7 @@
 		while(true)
 		{
 			System.out.print(
-			"\n"
+			"\n" +
 			" 1) add admin\n" +
 			" 2) add user\n" +
 			" 3) add book\n\n" +
@@ -1093,7 +1097,11 @@
 					return;
 				/* quit */
 				case 99:
-						return;
+						System.out.print("Are you sure? (y/N)> ");
+						s.nextLine();
+						if(s.nextLine().equals("y"))
+							return;
+						break;
 				default:
 					System.out.println("Invalid answer!, please try again.");
 					break;
@@ -1137,7 +1145,9 @@
 				pass = s.nextLine();
 			}while(pass.contains(" "));
 		}
-		return pass;
+
+		/* encrypt it! */
+		return Integer.toString(pass.hashCode());
 	}
 
 
@@ -1260,19 +1270,17 @@
 
 	public void ListAdmin()
 	{
-		System.out.println("Username | ID | Active | RegTime");
+		// System.out.println("Username | role | Reserved | ID | RegTime | Active | ");
+		for(AdminAttr i : AdminAttr.values())
+			System.out.print(i + " | ");
+		System.out.println();
+
 		for(Admin i : AdminList.values())
 		{
 			for(AdminAttr a : i.toMap().keySet())
-				System.out.print(i.toMap().get(a) + " | ");
+					System.out.print(i.toMap().get(a) + " | ");
 			System.out.println();
 		}
-/*
-			System.out.println(i.getUsername() + 
-			" | " + i.getID() +
-			" | " + i.Active +
-			" | " + i.getRegTime());
-*/
 	}
 
 	public void ListUser()