import java.io.*; public class login extends VMachine { private String username; public login () { } public void run() { FileClassLoader fileclass = null; fileclass = new FileClassLoader(); fileclass.bindir = "C:\\java\\OSVM\\bin\\"; boolean auth = false; int passcount = 0; String input = args[0]; String passwd = ""; if(input.compareTo("")==0) {// Initial input retrieval try { sysapi.Write(OUT,"login: "); input = sysapi.Read(IN); input = input.trim(); sysapi.Write(OUT,"password: "); passwd = sysapi.Read(IN); passwd = passwd.trim(); } catch(Exception ex) { System.out.println(ex); } } else {// Case parameter was a username try { sysapi.Write(OUT,"password: "); passwd = sysapi.Read(IN); passwd = passwd.trim(); } catch(Exception ex) { System.out.println(ex); } } while(sysapi.findUser(input) != null) {// Checks to see if user is logged in try { sysapi.Write(OUT,input + " Already Logged In.\n"); sysapi.Write(OUT,"login: "); input = sysapi.Read(IN); input = input.trim(); sysapi.Write(OUT,"password: "); passwd = sysapi.Read(IN); passwd = passwd.trim(); } catch(Exception ex) { System.out.println(ex); } } try { File passfile = new File("C:\\java\\OSVM\\sys\\pass"); passfile.createNewFile(); //Opens Password File for read access RandomAccessFile iostream = new RandomAccessFile(passfile,"r"); String line; do{// Loops until a valid username is found line = iostream.readLine(); if(line==null) { line=""; sysapi.Write(OUT,"Username not found.\n"); sysapi.Write(OUT,"login: "); input = sysapi.Read(IN); input = input.trim(); sysapi.Write(OUT,"password: "); passwd = sysapi.Read(IN); passwd = passwd.trim(); iostream.seek(0); } }while(! line.startsWith(input) || input.compareTo("")==0); //Found Suitable Username, now checking password do{// Loops until password is correct or 5 tries auth = line.endsWith(passwd); if(! auth || passwd.compareTo("")==0) { auth = false; sysapi.Write(OUT,"Password Incorrect\n"); sysapi.Write(OUT,"password: "); passwd = sysapi.Read(IN); passwd = passwd.trim(); passcount++; } }while(! auth && passcount < 5); } catch(Exception ex) { System.out.println(ex); } if(passcount < 5 && auth) {// Bypasses the rest of login creation if not authorized or passcount >= 5 try { File checkdir = new File("C:\\java\\OSVM\\usr\\" + input + "\\"); checkdir.mkdir(); } catch(Exception ex) { System.out.println(ex); } User newuser = new User(input,passwd); newuser.setcurrentPath("C:\\java\\OSVM\\usr\\" + input + "\\"); sysapi.setUser(newuser); if(((VMachine)vmh.getType()).Parent != null) {//Detaches this 'login' VM from previous User VM Tree and makes new tree within new User sysapi.Exit(vmh,owner); ((VMachine)vmh.getType()).Parent = null; IN = sysapi.OpenDevice("keyboard",input); OUT = sysapi.OpenDevice("display",input); } else { sysapi.setTitle(input); } try { sysapi.Write(OUT,"Welcome to OSVM, " + input + "\n"); } catch(Exception ex) { System.out.println(ex); } newuser.addHandle(vmh); try {//Loads Shell VM Class VMClass2 = fileclass.loadCmd("shell"); String[] args= new String[1]; args[0] = ""; Handle vmh2 = sysapi.CreateVM(IN,OUT,VMClass2,input,args,this,null,0); newuser.addHandle(vmh2); } catch(Exception ex) { System.out.println("Exception while creating new shell."); } sysapi.Compute(vmh); // Runs Shell sysapi.Exit(vmh,input); }// End of Passcount , authenticate if else {// Exits here if quitting login without a new user if(owner.compareTo("")!=0) {//Case not inital login sysapi.Exit(vmh,owner); } else { System.exit(0); } } } }