예제 #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);
        }
예제 #2
0
        public Session NewSession(Terminal terminal)
        {
            // ask the user to login
            int attempts = 0;

            do
            {
                try
                {
                    // prompt for user name
                    terminal.Echo = true;
                    terminal.Write("Hey, you! Log in. Username: "******"Username: "******"Enter Password: "******"");

                    // authenticate user
                    int UserID = security.Authenticate(username, password);

                    // create a new session and return it
                    SimpleSession session = new SimpleSession(security, filesystem, shells, terminal, UserID);
                    return(session);
                }
                catch (Exception ex)
                {
                    terminal.WriteLine("NOT authenticated");
                    attempts++;
                }
            }while (attempts < 3);
            // user failed authentication too many times
            terminal.WriteLine("Too many attempts! You're out.");
            return(null);
        }