Ejemplo n.º 1
0
        public AuthenticationResult Authenticate(IUnsafePacketReader credentialsReader, out IAccountSession session, out Account account)
        {
            session = null;
            account = null;

            var username = credentialsReader.ReadLengthString();
            if (username != "admin")
            {
                return AuthenticationResult.NotRegistered;
            }

            var password = credentialsReader.ReadLengthString();
            if (password != "admin")
            {
                return AuthenticationResult.IncorrectPassword;
            }

            session = new StubAccountSession();
            account = new Account()
                      {
                          AccountId = 1,
                          UserName = "******",
                          Password = "******",
                          Gender = Gender.Male,
                          GameMasterLevel = GameMasterLevel.GameMaster,
                          Status = AccountStatus.Active,
                          AccountPin = "0000",
                      };
            return AuthenticationResult.Success;
        }
Ejemplo n.º 2
0
        public AuthenticationResult Authenticate(IUnsafePacketReader credentialsReader, out IAccountSession session, out Account account)
        {
            session = null;
            account = null;

            var username = credentialsReader.ReadLengthString();

            if (username != "admin")
            {
                return(AuthenticationResult.NotRegistered);
            }

            var password = credentialsReader.ReadLengthString();

            if (password != "admin")
            {
                return(AuthenticationResult.IncorrectPassword);
            }

            session = new StubAccountSession();
            account = new Account()
            {
                AccountId       = 1,
                UserName        = "******",
                Password        = "******",
                Gender          = Gender.Male,
                GameMasterLevel = GameMasterLevel.GameMaster,
                Status          = AccountStatus.Active,
                AccountPin      = "0000",
            };
            return(AuthenticationResult.Success);
        }
Ejemplo n.º 3
0
 private bool CheckPin(IUnsafePacketReader reader)
 {
     string suggested = reader.ReadLengthString();
     string expected = Account.AccountPin;
     var isValid = suggested == expected;
     return isValid;
 }
Ejemplo n.º 4
0
 private bool CheckPin(IUnsafePacketReader reader)
 {
     string suggested = reader.ReadLengthString();
     string expected = this.Account.AccountPin;
     var isValid = suggested == expected;
     return isValid;
 }
Ejemplo n.º 5
0
        /// <inheritdoc />
        public AuthenticationResult Authenticate(IUnsafePacketReader credentialsReader, out IAccountSession session, out Account account)
        {
            // Default value for failure scenarios:
            session = null;

            // TODO: user name validation, throw IllegalPacketException if not valid
            var userName = credentialsReader.ReadLengthString();

            // Attempt to load the account.
            account = _accountProvider.LoadByUserName(userName);
            if (account == null)
            {
                // Fail with 'NotRegistered' if no account matches.
                return(AuthenticationResult.NotRegistered);
            }

            // TODO: password validation, throw IllegalPacketException if not valid
            var password = credentialsReader.ReadLengthString();

            string hash = LoginCrypto.GetMd5HashString(password, true);

            if (!string.Equals(hash, account.Password, StringComparison.Ordinal))
            {
                // Fail with 'IncorrectPassword' if password hash is bad.
                return(AuthenticationResult.IncorrectPassword);
            }

            // TODO: read other stuff from packet

            int sessionId;

            if (!_accountService.TryRegisterSession(account.AccountId, out sessionId))
            {
                // Fail with 'AlreadyLoggedIn' if there is another session running on this account.
                return(AuthenticationResult.AlreadyLoggedIn);
            }

            // Create the session.
            session = new AccountSession(_accountService, sessionId, account);
            return(AuthenticationResult.Success);
        }
Ejemplo n.º 6
0
        /// <inheritdoc />
        public AuthenticationResult Authenticate(IUnsafePacketReader credentialsReader, out IAccountSession session, out Account account)
        {
            // Default value for failure scenarios:
            session = null;

            // TODO: user name validation, throw IllegalPacketException if not valid
            var userName = credentialsReader.ReadLengthString();
            // Attempt to load the account.
            account = this.accountProvider.LoadByUserName(userName);
            if (account == null)
            {
                // Fail with 'NotRegistered' if no account matches.
                return AuthenticationResult.NotRegistered;
            }

            // TODO: password validation, throw IllegalPacketException if not valid
            var password = credentialsReader.ReadLengthString();

            string hash = LoginCrypto.GetMd5HashString(password, true);
            if (!string.Equals(hash, account.Password, StringComparison.Ordinal))
            {
                // Fail with 'IncorrectPassword' if password hash is bad.
                return AuthenticationResult.IncorrectPassword;
            }

            // TODO: read other stuff from packet

            int sessionId;
            if (!this.accountService.TryRegisterSession(account.AccountId, out sessionId))
            {
                // Fail with 'AlreadyLoggedIn' if there is another session running on this account.
                return AuthenticationResult.AlreadyLoggedIn;
            }

            // Create the session.
            session = new AccountSession(this.accountService, sessionId, account);
            return AuthenticationResult.Success;
        }