Java WriteShadow program to create SQLite database

A Java program called WriteShadow creates an SQLite database called “who” with a table called “shadow” that represents the Unix “shadow” file used for user login authentication.  A Clojure program called ReadShadow.clj displays various information about the shadow table.



The fields of a typical Unix shadow file are:

1. 1.Login ID 

2. 2.The hashed password 

3. 3.Date of last password change (days since Jan 1, 1970) 

4. 4.Minimum days required between password changes 

5. 5.Maximum days allowed between password changes 

6. 6.Days in advance to warn of password expiration 

7. 7.Days after password expiration to disable account 

8. 8.Account expiration date (days since Jan 1, 1970) 

9. 9.Failed login count and other reserved uses. 


For example, students of CSCI 2469 have the following loginID : passwordHash (truncated here) pair in /etc/shadow:


 advp11:$6$77yAdgsy$5An2M4XQP9 ...

 advp12:$1$jp8PZJAL$cJANKSaKWs ...

 advp13:$6$PosHc2vG$ZNG7w9UnaJ ...

 advp14:$6$x6z7VZ.r$8Flgu8Kg4OqK ...

 advp15:$6$zNoEfMGA$VjGO66crTh ...

 advp16:$6$0LLcedSK$3vtxGFiHxOU ...

 advp17:$6$i8i8eUVa$s1KryT87j1hE2 ...

 advp18:$6$F44kLeJn$oJK09.mi1pfoB ...

 advp19:$1$RpX825tP$XNf7qoAWgk/ ...


Note that within the passwordHash field are three sub fields delimited by the “$” sign.  These are:

1. 1.Hash algorithm id: 1=MD5, 2a=Blowfish, 2y=Blowfish, 5= SHA-256, 6=SHA-512 

2. 2.Salt: A random set of characters to append to password before hashing (Thwarts the hacker's rainbow tables; forces unique hash on re-used passwords).         

3. 3.The hash itself 


Your programs

A database who.sql (or who.db) has table called “shadow” consisting of three fields.  This file is generated entirely by the program below.  The fields of the shadow table are:

1. 1.Login ID 

2. 2.The hashed password (hash salt+password) 

3. 3.Date of last password change (days since Jan 1, 1970) ->  who.sql

1. 1.Creates shadow table in who.sql, if the table does not already exist. 

2. 2.Creates and modifies users in who.sql / shadow table. 

3. 3.Defines / uses lambdas in (or for) these methods: 

1. (a)addUser – Prompts for userID and password;  

1. i.Calls isUniqueID 

2. ii.Calls hashFunction 

2. (b)changePassword – calls validatePassword and then makePassword 

3. (c)makePassword: 

1. i.Calls hashFunction  

4. (d)validatePassword: 

1. i.Hashes user's password + salt (8 random characters) to check if resulting hash matches stored hash.  The salt can be made by converting random numbers to Unicode. see:    

2. ii.Displays "Authentication fail" or "Authentication OK." 

5. (e)isUniqueID – ensures user ID is unique. 

6. (f)removeUser 

7. (g)hashFunction: 

1. i.Appends random characters (the “salt”) with the password to ensure a unique hash.   

2. ii.Calls Java's SHA512 hash function.  See: 

3. iii.Converts the hash from hexadecimal to base64.  See:  

ReadShadow.clj -> who.sql

1. 1.Menu prompts to display: 

1. (a)The hash of a loginID. 

2. (b)List of all loginIDs. 

3. (c)Statistics – total loginIDs (Can use either built-in Clojure functions or SQL commands.). 


Optional task 1

Operations using lambdas bear a resemblance to command-line operations with pipes.  Accordingly, you can have data streams between Java, Clojure and SQLite programs.  For example, on the *nix command-line, data flow would be as follows:


        java WriteShadow  <  sqlite3 who.sql  |  clojure ReadShadow   

Need a custom answer at your budget?

This assignment has been answered 4 times in private sessions.

© 2021 Codify Tutor. All rights reserved