From e55c37728f183652eadd83b756a6134e2aa8134a Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Mon, 13 Apr 2015 11:33:04 -0600 Subject: [PATCH] Change config to refer to BCryptWorkFactor instead of WorkFactor. Change default work factor to 7. --- TShockAPI/ConfigFile.cs | 2 +- TShockAPI/DB/UserManager.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index 43f4a6f3..d01aea77 100755 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -399,7 +399,7 @@ namespace TShockAPI public bool SaveWorldOnLastPlayerExit = true; [Description("Determines the BCrypt work factor to use. If increased, all passwords will be upgraded to new work-factor on verify. Range: 5-31.")] - public int WorkFactor = 10; + public int BCryptWorkFactor = 7; /// /// Reads a configuration file from a given path diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs index 43386c81..18e95f03 100755 --- a/TShockAPI/DB/UserManager.cs +++ b/TShockAPI/DB/UserManager.cs @@ -374,7 +374,7 @@ namespace TShockAPI.DB // Convert the password to BCrypt, and save it. try { - this.Password = BCrypt.Net.BCrypt.HashPassword(password, TShock.Config.WorkFactor); + this.Password = BCrypt.Net.BCrypt.HashPassword(password, TShock.Config.BCryptWorkFactor); } catch (ArgumentOutOfRangeException) { TShock.Log.ConsoleError("Invalid BCrypt work factor! Upgrading user password to BCrypt using default work factor."); this.Password = BCrypt.Net.BCrypt.HashPassword(password); @@ -394,9 +394,9 @@ namespace TShockAPI.DB // If the destination work factor is not greater, we won't upgrade it or re-hash it int currentWorkFactor = Convert.ToInt32((this.Password.Split('$')[2])); - if (currentWorkFactor < TShock.Config.WorkFactor) { + if (currentWorkFactor < TShock.Config.BCryptWorkFactor) { try { - this.Password = BCrypt.Net.BCrypt.HashPassword(password, TShock.Config.WorkFactor); + this.Password = BCrypt.Net.BCrypt.HashPassword(password, TShock.Config.BCryptWorkFactor); } catch (ArgumentOutOfRangeException) { TShock.Log.ConsoleError("Invalid BCrypt work factor! Refusing to change work-factor on exsting password."); } @@ -411,7 +411,7 @@ namespace TShockAPI.DB public void CreateBCryptHash(string password) { try { - this.Password = BCrypt.Net.BCrypt.HashPassword(password, TShock.Config.WorkFactor); + this.Password = BCrypt.Net.BCrypt.HashPassword(password, TShock.Config.BCryptWorkFactor); } catch (ArgumentOutOfRangeException) { TShock.Log.ConsoleError("Invalid BCrypt work factor! Creating new hash using default work factor."); this.Password = BCrypt.Net.BCrypt.HashPassword(password);