// -------------------------------------------------------------------------------
        // OnClientMessageRequestUserChangePassword
        // @Client -> @Server
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Event <c>OnClientMessageRequestUserChangePassword</c>.
        /// Triggered when the server receives a user change password request.
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="msg"></param>
        void OnClientMessageRequestUserChangePassword(NetworkConnection conn, ClientMessageRequestUserChangePassword msg)
        {
            ServerMessageResponseUserChangePassword message = new ServerMessageResponseUserChangePassword
            {
                success          = true,
                text             = "",
                causesDisconnect = false
            };

            if (!GetIsUserLoggedIn(msg.userName) && DatabaseManager.singleton.TryUserChangePassword(msg.userName, msg.oldPassword, msg.newPassword))
            {
                message.text = systemText.userChangePasswordSuccess;

                debug.LogFormat(this.name, nameof(OnClientMessageRequestUserChangePassword), conn.ID(), "Success");                 //DEBUG
            }
            else
            {
                message.text    = systemText.userChangePasswordFailure;
                message.success = false;

                debug.LogFormat(this.name, nameof(OnClientMessageRequestUserChangePassword), conn.ID(), "DENIED");                 //DEBUG
            }

            conn.Send(message);
        }
Ejemplo n.º 2
0
        // -------------------------------------------------------------------------------
        // RequestUserChangePassword
        // @Client
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Protected override function <c>RequestUserChangePassword</c> that returns a boolean.
        /// Sends a user change password request to the server.
        /// Checks whether the user change password request is valid and can be sent to the server.
        /// Returns a boolean detailing whether the request was sent or not.
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="userName"></param>
        /// <param name="oldpassword"></param>
        /// <param name="newpassword"></param>
        /// <returns> Returns a boolean detailing whether the request was sent to the server. </returns>
        protected override bool RequestUserChangePassword(NetworkConnection conn, string userName, string oldpassword, string newpassword)
        {
            if (!base.RequestUserChangePassword(conn, userName, oldpassword, newpassword))
            {
                return(false);
            }

            ClientMessageRequestUserChangePassword message = new ClientMessageRequestUserChangePassword
            {
                username    = name,
                oldPassword = Tools.GenerateHash(userName, oldpassword),
                newPassword = Tools.GenerateHash(userName, newpassword)
            };

            // reset player prefs on password change
            PlayerPrefs.SetString(Constants.PlayerPrefsPassword, "");

            conn.Send(message);

            debug.LogFormat(this.name, nameof(RequestUserChangePassword), conn.Id(), userName);             //DEBUG

            return(true);
        }