Pick password randomly for both levels

// I imported Random function in the code in order to generate random password. Although Random.Range(0,Level1pass.Lenth) is much more efficient than Random.Range(0,4)//

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;

public class HackerFive : MonoBehaviour
{
    //Game Configuration
    string[] Level1pass = { "pant", "hard", "motor", "door","tree" };
    string[] Level2pass = { "actor", "heavy", "share", "horse","build" };
    //Game Statistic
    int Level;
    string password;
    enum Screen { MainMenu, Password, Win }
    Screen currentScreen;
    // Start is called before the first frame update
    void Start()
    {
        Starter();
    }

    void Starter()
    {
        currentScreen = Screen.MainMenu;
        print("HELLO CONSOLE!");
        Terminal.ClearScreen();
        Terminal.WriteLine("Hello Hacker!");
        Terminal.WriteLine("Hackserver: Database to hack...");
        Terminal.WriteLine(" ");
        Terminal.WriteLine("* Press 1 for Local Police Files");
        Terminal.WriteLine("* Press 2 for CBI Files");
        Terminal.WriteLine("* Press 3 for ISRO Satelite Data");
        Terminal.WriteLine(" ");
        Terminal.WriteLine("Enter your selection: ");

    }

    void OnUserInput(string input)
    {
        if (input == "menu")
        {
            Starter();
        }
        else if (currentScreen == Screen.MainMenu)
        {
            NewMethod(input);
        }
        else if (currentScreen == Screen.Password)
        {
            NewPass(input);
        }
        else if (currentScreen == Screen.Win)
        {
            Stoped(input);
        }
    }

    void NewMethod(string input)
    {
        bool ValidLevel = (input == "1" || input == "2");
        if (ValidLevel)
        {
            Level = int.Parse(input);
            NewGame();
            print(input == "1");//true
        }
        else if (input == "007")
        {
            Terminal.WriteLine("Code number - 007");
            Terminal.WriteLine("A Royal Naval Reserve Commander.");
            Terminal.WriteLine("A double Agent");
        }

        else
        { Terminal.WriteLine("Please enter a valid number"); }
    }

    void NewGame()
    {
        currentScreen = Screen.Password;

        Terminal.ClearScreen();
        Terminal.WriteLine("You have choosen level " + Level);
        Terminal.WriteLine("Please type the password!");
        switch (Level)
        {
            case 1:
                password = Level1pass[Random.Range(0,4)];
                break;
            case 2:
                password = Level2pass[Random.Range(0,4)];
                break;
            default:
                Debug.LogError("INVALID LEVEL NUMBER");
                break;
        }
    }
    void NewPass(string input)
    {
        switch (input == password)
        {
            case true:
                Terminal.WriteLine("Congratulation! You have won Level " + Level + "!!!");
                Terminal.WriteLine("Press Enter to continue...");
                Stoped(input);
                break;
            default:
                Terminal.WriteLine("Incorrect Password!!!");
                break;
        }
    }
    void Stoped(string input)
    {
        currentScreen = Screen.Win;
        switch (input)
        {
            case "":
                Starter();
                break;
            case " ":
                Terminal.WriteLine("Reaturn to MAINMENU");
                break;
        }
    }

    // Update is called once per frame
    void Update()
    {
        //password = Level1pass[Random.Range(0, 4)];
        //Terminal.WriteLine(password);
    }
}

Privacy & Terms