Making our OS - Login System, Custom Installer, and System Files

## A little intro

I have taken the liberty of combining three in one and finishing up this tutorial. So without further ado, let's get started.
lo

## Login

First, the login. The coding is really simple. Like, really simple. Add this to your BeforeRun():

```
    E:
    string password = "tutOS_user";
    string input = Console.ReadLine();
    if (input == password) {
         Console.Clear();
         Run();
    }
    else {
         Console.WriteLine("WRONG PASSWORD. TRY AGAIN!");
         goto E;
    }

```

When you run your OS, it will prompt you to enter a password. Enter the correct password and enjoy your OS!

## System Files

I have decided to do this one first because it makes sense, and you'll see why in a minute.

In your BeforeRun() before the login add this:

```
    Console.WriteLine("tutOS [0.0.1]");
    if (!File.Exists("0:\\SYSTEM\\System.cs")) {
         //Custom Installer (Now you see why
         Kernel.Stop(); // There is no SYSTEM directory yet, so we just shut the computer down there
    } else {
         File.ReadAllText("0:\\SYSTEM\\System.cs");
    }
    Console.WriteLine("Loading Filesystem...");
    Console.Clear();
    string loading_text = "Booting";
    Console.WriteLine(loading_text);
    File.ReadAllText("0:\\SYSTEM\\users.db");
    loading_text += ".";
    File.ReadAllText("0:\\SYSTEM\\readme.txt");
    loading_text += ".";
    File.ReadAllText("0:\\SYSTEM\\sysinfo.txt");
    loading_text += ".";
    File.ReadAllText("0:\\SYSTEM\\users.db"); // Right here it starts to loop
    loading_text += ".";
    File.ReadAllText("0:\\SYSTEM\\readme.txt");
    loading_text += ".";
    File.ReadAllText("0:\\SYSTEM\\sysinfo.txt");
    loading_text += ".";

```

Now if you boot your OS, it will shutdown immediately, for we have no SYSTEM directory. Now let's move on to the Custom Installer.

## Custom Installer

Let's create a custom installer for our OS. Here is the code:

```
    //This is in the if.. statement. Remove the Kernel.Stop();
    string write;/*This is so the OS knows whether to install Tut-Pad*/
    Console.Clear();
    Console.WriteLine("-----tutOS Installer-----");
    Console.WriteLine("Create a username and password:");
    Console.Write("Username: ");
    string username = Console.ReadLine();
    Console.Write("Password: ");
    string cPassword = Console.ReadLine();
    Console.WriteLine("Would you like to install Tut-Pad? Y/N");
    Console.Write("> ");
    string yon/*Stands for Yes or NO*/ = Console.ReadLine();
    if (yon == "Y" || yon == "y") {
         write = "tut pad";
    } else if (yon == "N" || yon == "n") {
         write = "write";
    } else {
         Sys.Power.Reboot();
    }
    Console.WriteLine("Starting Installation Process...");
    Console.WriteLine("Creating System Directory...");
    fs.CreateDirectory("0:\\SYSTEM\\");
    Console.WriteLine("Creating System Files");
    fs.CreateFile("0:\\SYSTEM\\System.cs");
    fs.CreateFile("0:\\SYSTEM\\users.db");
    fs.CreateFile("0:\\SYSTEM\\readme.txt");
    fs.CreateFile("0:\\SYSTEM\\sysinfo.txt");
    Console.WriteLine("Setting User Preferences...");
    File.WriteAllText("0:\\SYSTEM\\System.cs", "using tutOS.System; namespace System {
    class System { public void Main(){ Console.WriteLine("System File. Do not edit./*You
    can add your entire Kernel code here.*/") } } }")
    File.WriteAllText("0:\\SYSTEM\\users.db", write.Split("\n")); //sometimes it have a bug
    File.WriteAllText("0:\\SYSTEM\\readme.txt", "You can put your license here!");
    File.WriteAllText("0:\\SYSTEM\\sysinfo.txt", "tutOS Version 0.0.1 [8 GB]");
    fs.CreateDirectory("0:\\Documents\\");
    Console.WriteLine("Deleting Preinstalled CosmosVFS Files")
    fs.DeleteDirectory("0:\\Dir Testing\\");
    fs.DeleteDirectory("0:\\TEST\\");
    File.Delete("0:\\Kudzu.txt");
    File.Delete("0:\\Root.txt");
    Console.Write("Press any key to reboot...");
    Sys.Power.Reboot();

```

Well, that was a lot. I wasn't expecting that.

## Are we there yet?

No. Actually, we got one more step to go. Releasing and Extras. We will also be looking at the Cosmos Graphical Subsystem. I will also continue with Under the Hood and WinForms. Let's continue with WinForms.