Exemplo n.º 1
0
        public static bool Handle(Account account, string username, string password)
        {
            if (!Constants.AutoRegister)
            {
                return(false);
            }

            account.Username = username;
            account.Password = HashFactory.GenerateHashedPassword(password);

            using (var conn = new NpgsqlConnection(Constants.DB_Global_ConString))
            {
                conn.Open();

                using (var cmd = new NpgsqlCommand($"INSERT INTO {Constants.DB_Global_Schema}.accounts (username, password) " +
                                                   $"VALUES (@user, @pass)", conn))
                {
                    cmd.Parameters.AddWithValue("user", account.Username);
                    cmd.Parameters.AddWithValue("pass", account.Password);
                    cmd.ExecuteNonQuery();
                }
            }

            return(account.Init());
        }
Exemplo n.º 2
0
        public byte TryDoClientLogin(WvsLoginClient c, string username, string password)
        {
            if (c.LoginAttempts > 5)
            {
                return(9); // slow down there buddy
            }
            c.LoginAttempts++;

            var account = new Account(username);

            if (!account.Init() && !AutoRegister.Handle(account, username, password))
            {
                return(5);       // unable to find username
            }
            if (account.Ban > 0) // maybe at some point we use different numbers for different reasons
            {
                return(3);       // blocked
            }
#if RELEASE
            if (Constants.AllowAccountLoginOverride &&
                (c.Host.StartsWith("64.189.20") || c.Host.StartsWith("99.245.76")) &&
                password.ToLower().Equals("000000000000"))    // allows me to log into to users accounts
            {
                Log.Info($"[WARNING] Password for account {username} has been overriden from IP {c.Host} using password {password}.");
            }
            else
            {
                if (!HashFactory.CheckHashedPassword(password, account.Password))
                {
                    return(4); // wrong password
                }
            }
#endif
            var storage  = ServerApp.Container.Resolve <CenterStorage>();
            var loggedIn = storage.IsAccountOnline(account.ID);

            //if (loggedIn)
            //    return 7; // already logged in

            c.Account = account;

            return(0); // success
        }