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 <old> <new> wouldn't update the user's password
This commit is contained in:
White 2015-05-27 18:29:29 +09:30
parent c918d851b0
commit e33b6ebebc
4 changed files with 30 additions and 12 deletions

View file

@ -888,15 +888,23 @@ namespace TShockAPI
string password = args.Parameters[0]; string password = args.Parameters[0];
if (args.Player.User.VerifyPassword(password)) if (args.Player.User.VerifyPassword(password))
{ {
args.Player.SendSuccessMessage("You changed your password!"); try
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 + "."); 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 else
{ {
args.Player.SendErrorMessage("You failed to change your password!"); 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: " + 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 else
@ -1066,12 +1074,16 @@ namespace TShockAPI
args.Player.SendErrorMessage("Password change for " + user.Name + " failed! Check console!"); args.Player.SendErrorMessage("Password change for " + user.Name + " failed! Check console!");
TShock.Log.ConsoleError(e.ToString()); 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 // Group changing requires a username or IP address, and a new group to set
else if (subcmd == "group" && args.Parameters.Count == 3) else if (subcmd == "group" && args.Parameters.Count == 3)
{ {
var user = new User(); var user = new User();
user.Name = args.Parameters[1]; user.Name = args.Parameters[1];
try try
{ {

View file

@ -118,6 +118,8 @@ namespace TShockAPI.DB
{ {
try try
{ {
user.CreateBCryptHash(password);
if ( if (
_database.Query("UPDATE Users SET Password = @0 WHERE Username = @1;", user.Password, _database.Query("UPDATE Users SET Password = @0 WHERE Username = @1;", user.Password,
user.Name) == 0) user.Name) == 0)

View file

@ -1,7 +1,7 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // 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 // Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated. // the code is regenerated.

View file

@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TShockAPI</RootNamespace> <RootNamespace>TShockAPI</RootNamespace>
<AssemblyName>TShockAPI</AssemblyName> <AssemblyName>TShockAPI</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper> <IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl> <PublishUrl>publish\</PublishUrl>
@ -27,6 +27,7 @@
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@ -39,6 +40,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>bin\Debug\TShockAPI.XML</DocumentationFile> <DocumentationFile>bin\Debug\TShockAPI.XML</DocumentationFile>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
<!-- <NoWarn>1591</NoWarn> --> <!-- <NoWarn>1591</NoWarn> -->
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
@ -51,6 +53,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>bin\Release\TShockAPI.XML</DocumentationFile> <DocumentationFile>bin\Release\TShockAPI.XML</DocumentationFile>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="HttpServer"> <Reference Include="HttpServer">
@ -64,12 +67,13 @@
<HintPath>..\prebuilts\MySql.Data.dll</HintPath> <HintPath>..\prebuilts\MySql.Data.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\prebuilts\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="BCrypt.Net"> <Reference Include="BCrypt.Net">
<HintPath>..\prebuilts\BCrypt.Net.dll</HintPath> <HintPath>..\prebuilts\BCrypt.Net.dll</HintPath>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\prebuilts\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Web" /> <Reference Include="System.Web" />
@ -189,7 +193,7 @@
</PropertyGroup> </PropertyGroup>
<ProjectExtensions> <ProjectExtensions>
<VisualStudio> <VisualStudio>
<UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildAction="Both" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_StartDate="2011/6/17" BuildVersion_IncrementBeforeBuild="False" /> <UserProperties BuildVersion_IncrementBeforeBuild="False" BuildVersion_StartDate="2011/6/17" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_BuildAction="Both" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" />
</VisualStudio> </VisualStudio>
</ProjectExtensions> </ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.