Example #1
0
        public Session NewSession(Terminal terminal)
        {
            const int MAX_TRIES = 3;

            // ask the user to login
            for (int attempts = 0; attempts < MAX_TRIES; attempts++)
            {
                try
                {
                    //prompt for username
                    terminal.Write("Username: "******"Set Password: "******"Password: "******"Welcome! " + security.UserName(userId));


                    return(new SimpleSession(security, this.filesystem, this.shells, terminal, userId));
                }
                catch (Exception ex)
                {
                    terminal.WriteLine("Nope!");
                }
            }


            terminal.WriteLine("Failed login attempts!");
            return(null);
        }
Example #2
0
        private void SetNewPassword(string username, Terminal terminal, int maxTries)
        {
            int tries = 0;

            do
            {
                try
                {
                    // prompt for new password
                    terminal.Echo = false;
                    terminal.Write("Enter New Password: "******"Invalid password: "******"Failed to set new password!");
        }
Example #3
0
        static void CreatePete(SecuritySystem security, FileSystem filesystem)
        {
            // add user steven if not already there
            int peteUserID = -1;

            try
            {
                peteUserID = security.UserID("steven");
            }
            catch (Exception)
            {
                peteUserID = security.AddUser("steven");
                security.SetPassword("steven", "foobar42");
            }

            // create some test files for user pete if needed
            if (filesystem.Find(security.UserHomeDirectory(peteUserID)) != null)
            {
                try
                {
                    Directory peteDir = (Directory)filesystem.Find(security.UserHomeDirectory(peteUserID));

                    Directory  subDir  = peteDir.CreateDirectory("subdir");
                    File       file1   = subDir.CreateFile("file1");
                    File       file2   = subDir.CreateFile("file2");
                    FileStream stream1 = file1.Open();
                    stream1.Write(0, ASCIIEncoding.ASCII.GetBytes("hello from file 1!"));
                    stream1.Close();
                    FileStream stream2 = file2.Open();
                    stream2.Write(0, ASCIIEncoding.ASCII.GetBytes("back at you from file 2!"));
                    stream2.Close();
                }
                catch (Exception)
                {
                    // Nothing here
                }
            }
        }