ForumServer.ServerController.Login C# (CSharp) Method

Login() public method

public Login ( string username, string password ) : AuthorizationLevel
username string
password string
return AuthorizationLevel
        public AuthorizationLevel Login(string username, string password)
        {
            try
            {
                log.Info("got request to login from user " + username + " and password *******");
                if (securityManager.AuthorizedLogin(username, password) == Result.OK)
                    return dataManager.GetUser(username).Level;
                else return AuthorizationLevel.GUEST;
            }
            catch (Exception e)
            {
                log.Error("failed to login user " + username, e);
                throw e;
            }
        }

Usage Example

Ejemplo n.º 1
0
        public void LoginRegisterTests()
        {
            ServerController sc = new ServerController();

            Assert.AreEqual(Result.USER_NOT_FOUND, sc.Login("user1", "123456"));//login before register

            Assert.AreEqual(Result.SECURITY_ERROR, sc.Register("alice", "123456"));

            //login tests
            for (int i = 0; i < 100; i++)
            {
                // try to register twice with same userName

                Assert.AreEqual(Result.SECURITY_ERROR, sc.Register("alice" + i, "123456"));
                Assert.AreEqual(Result.SECURITY_ERROR, sc.Register("alice" + i, "123456"));

                //failed: try to login twice with same userName return true , should return false.
                Assert.AreEqual(Result.OK, sc.Login("alice" + i, "123456"));
                //Assert.IsFalse(sc.Login("alice" + i, "123456"));

                Assert.AreEqual(Result.USER_NOT_FOUND, sc.Login("bob" + i, "123456"));//try to login with bad unknown user
                Assert.AreEqual(Result.SECURITY_ERROR, sc.Login("alice" + i, "123456" + i));//try to login with bad password
            }
        }
All Usage Examples Of ForumServer.ServerController::Login