//File: newusr.java //CS 471 - Operating Systems Project //Dennis Pereira, Ely Soto, John Cavalieri //The newusr command prompts the user for the information necessary //to add a new user to the login file //it will allow the new user to login in future sessions //and it will put the user's password into the password file import java.io.*; public class newusr extends VMachine { /* Creates new newusr */ public newusr() { } public void run() { try { //var to see if the user already exists int match = 0; //prompt user for new user name sysapi.Write(OUT,"Please enter your username (No spaces): "); //read input String newusrname = sysapi.Read(IN); //vars used to compare password confirmation String password1; String password2; do { //password confirmation sysapi.Write(OUT,"Please enter your password (No spaces):"); password1 = sysapi.Read(IN); sysapi.Write(OUT,"Please reenter your password: "); password2 = sysapi.Read(IN); //test that passwords match if(password1.compareTo(password2)==0) { match=1; } else { //passwords don't match, loop until they do sysapi.Write(OUT,"Passwords do not match.\n"); } }while(match==0); //loop until passwords match //create a password file for the user File passfile = new File("C:\\java\\OSVM\\sys\\pass"); passfile.createNewFile(); //make the file editable RandomAccessFile iostream = new RandomAccessFile(passfile,"rw"); iostream.seek(iostream.length()); //add the user and password the the file iostream.writeBytes(newusrname + " " + password1 + "\n"); } catch(Exception ex) { //something bad happened, croak with message System.out.println("newusr threw Exception: " + ex); } sysapi.Exit(vmh,owner); } }