TShockAPI.DB.User.UpgradePasswordWorkFactor C# (CSharp) Method

UpgradePasswordWorkFactor() protected method

Upgrades a password to the highest work factor available in the config.
protected UpgradePasswordWorkFactor ( string password ) : void
password string The raw user password (unhashed) to upgrade
return void
        protected void UpgradePasswordWorkFactor(string password)
        {
            // If the destination work factor is not greater, we won't upgrade it or re-hash it
            int currentWorkFactor;
            try
            {
                currentWorkFactor = Int32.Parse((Password.Split('$')[2]));
            }
            catch (FormatException)
            {
                TShock.Log.ConsoleError("Warning: Not upgrading work factor because bcrypt hash in an invalid format.");
                return;
            }

            if (currentWorkFactor < TShock.Config.BCryptWorkFactor)
            {
                try
                {
                    TShock.Users.SetUserPassword(this, password);
                }
                catch (UserManagerException e)
                {
                    TShock.Log.ConsoleError(e.ToString());
                }
            }
        }