Beispiel #1
0
        public static async Task Register(Player player, string user, string pass)
        {
            var results = await database.Query("SELECT id FROM users WHERE username = ?", user);

            if (results.Length < 1)
            {
                string password = await Bcrypt.Hash(pass);

                database.Exec("INSERT INTO `users` (`username`, `password`) VALUES (?, ?)", user, password);
                var results2 = await database.Query("SELECT id FROM users WHERE username = ?", user);
                await AttemptPlayerRelog(player, results2[0]["id"]);
            }
            else
            {
                ChatBox.WriteLine("That username has been taken.", player, Slipe.Shared.Utilities.Color.Red);
            }
        }
Beispiel #2
0
        private async void HandleRegister(Player source, RegisterRpc rpc)
        {
            if (rpc.Password != rpc.PasswordConfirmation)
            {
                RpcManager.Instance.TriggerRPC(source, "Register.Error", new ErrorRpc("These passwords are not the same."));
                return;
            }

            if (string.IsNullOrEmpty(rpc.Username) || string.IsNullOrEmpty(rpc.Password) || string.IsNullOrEmpty(rpc.Email))
            {
                RpcManager.Instance.TriggerRPC(source, "Register.Error", new ErrorRpc("Please fill in the entire form."));
                return;
            }

            if (!(rpc.Email.Contains("@") && rpc.Email.Contains(".")))
            {
                RpcManager.Instance.TriggerRPC(source, "Register.Error", new ErrorRpc("Please fill in a valid email."));
                return;
            }

            if ((await database.Query("SELECT id FROM `users` WHERE email = ?", rpc.Email)).Length > 0)
            {
                RpcManager.Instance.TriggerRPC(source, "Register.Error", new ErrorRpc("This email address is already in use."));
                return;
            }

            if ((await database.Query("SELECT id FROM `users` WHERE username = ?", rpc.Username)).Length > 0)
            {
                RpcManager.Instance.TriggerRPC(source, "Register.Error", new ErrorRpc("This username address is already in use."));
                return;
            }

            string hash = await Bcrypt.Hash(rpc.Password);

            database.Exec("INSERT INTO `users` (`username`, `email`, `password`) VALUES (?, ?, ?)", rpc.Username, rpc.Email, hash);

            RpcManager.Instance.TriggerRPC(source, "Register.Success", new EmptyRpc());
        }