From e33b6ebebc49c5d058d5643a91e8447d68008abf Mon Sep 17 00:00:00 2001 From: White Date: Wed, 27 May 2015 18:29:29 +0930 Subject: [PATCH] Now targets NET 4.5, so the solution actually compiles. Fixed an issue where /user password sets a blank string in the database Fixed an issue where /password wouldn't update the user's password --- TShockAPI/Commands.cs | 24 ++++++++++++++++++------ TShockAPI/DB/UserManager.cs | 2 ++ TShockAPI/Resources.Designer.cs | 2 +- TShockAPI/TShockAPI.csproj | 14 +++++++++----- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index c9b840a0..27e15743 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -888,15 +888,23 @@ namespace TShockAPI string password = args.Parameters[0]; if (args.Player.User.VerifyPassword(password)) { - args.Player.SendSuccessMessage("You changed your password!"); - TShock.Users.SetUserPassword(args.Player.User, args.Parameters[1]); // SetUserPassword will hash it for you. - TShock.Log.ConsoleInfo(args.Player.IP + " named " + args.Player.Name + " changed the password of account " + args.Player.User.Name + "."); + try + { + args.Player.SendSuccessMessage("You changed your password!"); + TShock.Users.SetUserPassword(args.Player.User, args.Parameters[1]); // SetUserPassword will hash it for you. + TShock.Log.ConsoleInfo(args.Player.IP + " named " + args.Player.Name + " changed the password of account " + + args.Player.User.Name + "."); + } + catch (ArgumentOutOfRangeException) + { + args.Player.SendErrorMessage("Password must be greater than or equal to " + TShock.Config.MinimumPasswordLength + " characters."); + } } else { args.Player.SendErrorMessage("You failed to change your password!"); TShock.Log.ConsoleError(args.Player.IP + " named " + args.Player.Name + " failed to change password for account: " + - args.Player.User.Name + "."); + args.Player.User.Name + "."); } } else @@ -1066,12 +1074,16 @@ namespace TShockAPI args.Player.SendErrorMessage("Password change for " + user.Name + " failed! Check console!"); TShock.Log.ConsoleError(e.ToString()); } + catch (ArgumentOutOfRangeException) + { + args.Player.SendErrorMessage("Password must be greater than or equal to " + TShock.Config.MinimumPasswordLength + " characters."); + } } // Group changing requires a username or IP address, and a new group to set else if (subcmd == "group" && args.Parameters.Count == 3) { - var user = new User(); - user.Name = args.Parameters[1]; + var user = new User(); + user.Name = args.Parameters[1]; try { diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs index f44ca38b..4aa66c96 100755 --- a/TShockAPI/DB/UserManager.cs +++ b/TShockAPI/DB/UserManager.cs @@ -118,6 +118,8 @@ namespace TShockAPI.DB { try { + user.CreateBCryptHash(password); + if ( _database.Query("UPDATE Users SET Password = @0 WHERE Username = @1;", user.Password, user.Name) == 0) diff --git a/TShockAPI/Resources.Designer.cs b/TShockAPI/Resources.Designer.cs index b4b9e8f4..49c1d908 100644 --- a/TShockAPI/Resources.Designer.cs +++ b/TShockAPI/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.17929 +// Runtime Version:4.0.30319.34209 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index 68584c5f..19d2265b 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -10,7 +10,7 @@ Properties TShockAPI TShockAPI - v4.0 + v4.5 512 false publish\ @@ -27,6 +27,7 @@ 1.0.0.%2a false true + true @@ -39,6 +40,7 @@ true bin\Debug\TShockAPI.XML x86 + false @@ -51,6 +53,7 @@ true bin\Release\TShockAPI.XML x86 + false @@ -64,12 +67,13 @@ ..\prebuilts\MySql.Data.dll True - - ..\prebuilts\Newtonsoft.Json.dll - ..\prebuilts\BCrypt.Net.dll + + False + ..\prebuilts\Newtonsoft.Json.dll + @@ -189,7 +193,7 @@ - +