From dc4f255e0fab5f6b39b7add197830591b89103c0 Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 25 Apr 2021 21:37:52 +0800 Subject: ... --- .../Resources/Services/Exception.Designer.cs | 234 --------------------- BackEnd/Timeline/Resources/Services/Exception.resx | 177 ---------------- .../Token/JwtUserTokenBadFormatException.cs | 16 +- .../Timeline/Services/Token/Resource.Designer.cs | 162 ++++++++++++++ BackEnd/Timeline/Services/Token/Resource.resx | 153 ++++++++++++++ .../Timeline/Services/Token/UserTokenException.cs | 27 ++- .../Services/User/PasswordBadFormatException.cs | 26 --- BackEnd/Timeline/Services/User/PasswordService.cs | 24 +-- .../Timeline/Services/User/Resource.Designer.cs | 63 ++++++ BackEnd/Timeline/Services/User/Resource.resx | 21 ++ BackEnd/Timeline/Timeline.csproj | 18 +- 11 files changed, 437 insertions(+), 484 deletions(-) delete mode 100644 BackEnd/Timeline/Resources/Services/Exception.Designer.cs delete mode 100644 BackEnd/Timeline/Resources/Services/Exception.resx create mode 100644 BackEnd/Timeline/Services/Token/Resource.Designer.cs create mode 100644 BackEnd/Timeline/Services/Token/Resource.resx delete mode 100644 BackEnd/Timeline/Services/User/PasswordBadFormatException.cs (limited to 'BackEnd/Timeline') diff --git a/BackEnd/Timeline/Resources/Services/Exception.Designer.cs b/BackEnd/Timeline/Resources/Services/Exception.Designer.cs deleted file mode 100644 index 21ca7b86..00000000 --- a/BackEnd/Timeline/Resources/Services/Exception.Designer.cs +++ /dev/null @@ -1,234 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Timeline.Resources.Services { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Exception { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Exception() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Services.Exception", typeof(Exception).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to The password is wrong.. - /// - internal static string BadPasswordException { - get { - return ResourceManager.GetString("BadPasswordException", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The hashes password is of bad format. It might not be created by server.. - /// - internal static string HashedPasswordBadFromatException { - get { - return ResourceManager.GetString("HashedPasswordBadFromatException", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Not of valid base64 format. See inner exception.. - /// - internal static string HashedPasswordBadFromatExceptionNotBase64 { - get { - return ResourceManager.GetString("HashedPasswordBadFromatExceptionNotBase64", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Decoded hashed password is of length 0.. - /// - internal static string HashedPasswordBadFromatExceptionNotLength0 { - get { - return ResourceManager.GetString("HashedPasswordBadFromatExceptionNotLength0", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to See inner exception.. - /// - internal static string HashedPasswordBadFromatExceptionNotOthers { - get { - return ResourceManager.GetString("HashedPasswordBadFromatExceptionNotOthers", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Salt length < 128 bits.. - /// - internal static string HashedPasswordBadFromatExceptionNotSaltTooShort { - get { - return ResourceManager.GetString("HashedPasswordBadFromatExceptionNotSaltTooShort", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Subkey length < 128 bits.. - /// - internal static string HashedPasswordBadFromatExceptionNotSubkeyTooShort { - get { - return ResourceManager.GetString("HashedPasswordBadFromatExceptionNotSubkeyTooShort", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Unknown format marker.. - /// - internal static string HashedPasswordBadFromatExceptionNotUnknownMarker { - get { - return ResourceManager.GetString("HashedPasswordBadFromatExceptionNotUnknownMarker", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The token didn't pass verification because {0}.. - /// - internal static string JwtUserTokenBadFormatException { - get { - return ResourceManager.GetString("JwtUserTokenBadFormatException", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to id claim is not a number. - /// - internal static string JwtUserTokenBadFormatExceptionIdBadFormat { - get { - return ResourceManager.GetString("JwtUserTokenBadFormatExceptionIdBadFormat", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to id claim does not exist. - /// - internal static string JwtUserTokenBadFormatExceptionIdMissing { - get { - return ResourceManager.GetString("JwtUserTokenBadFormatExceptionIdMissing", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to other error, see inner exception for information. - /// - internal static string JwtUserTokenBadFormatExceptionOthers { - get { - return ResourceManager.GetString("JwtUserTokenBadFormatExceptionOthers", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to unknown error. - /// - internal static string JwtUserTokenBadFormatExceptionUnknown { - get { - return ResourceManager.GetString("JwtUserTokenBadFormatExceptionUnknown", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to version claim is not a number.. - /// - internal static string JwtUserTokenBadFormatExceptionVersionBadFormat { - get { - return ResourceManager.GetString("JwtUserTokenBadFormatExceptionVersionBadFormat", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to version claim does not exist.. - /// - internal static string JwtUserTokenBadFormatExceptionVersionMissing { - get { - return ResourceManager.GetString("JwtUserTokenBadFormatExceptionVersionMissing", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Password is of bad format.. - /// - internal static string PasswordBadFormatException { - get { - return ResourceManager.GetString("PasswordBadFormatException", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The token is of bad format, which means it may not be created by the server.. - /// - internal static string UserTokenBadFormatException { - get { - return ResourceManager.GetString("UserTokenBadFormatException", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The token is of bad version.. - /// - internal static string UserTokenBadVersionException { - get { - return ResourceManager.GetString("UserTokenBadVersionException", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The token is expired because its expiration time has passed.. - /// - internal static string UserTokenTimeExpireException { - get { - return ResourceManager.GetString("UserTokenTimeExpireException", resourceCulture); - } - } - } -} diff --git a/BackEnd/Timeline/Resources/Services/Exception.resx b/BackEnd/Timeline/Resources/Services/Exception.resx deleted file mode 100644 index c31ed7c7..00000000 --- a/BackEnd/Timeline/Resources/Services/Exception.resx +++ /dev/null @@ -1,177 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - The password is wrong. - - - The hashes password is of bad format. It might not be created by server. - - - Not of valid base64 format. See inner exception. - - - Decoded hashed password is of length 0. - - - See inner exception. - - - Salt length < 128 bits. - - - Subkey length < 128 bits. - - - Unknown format marker. - - - The token didn't pass verification because {0}. - - - id claim is not a number - - - id claim does not exist - - - other error, see inner exception for information - - - unknown error - - - version claim is not a number. - - - version claim does not exist. - - - Password is of bad format. - - - The token is of bad format, which means it may not be created by the server. - - - The token is of bad version. - - - The token is expired because its expiration time has passed. - - \ No newline at end of file diff --git a/BackEnd/Timeline/Services/Token/JwtUserTokenBadFormatException.cs b/BackEnd/Timeline/Services/Token/JwtUserTokenBadFormatException.cs index 4d7300a1..7d272170 100644 --- a/BackEnd/Timeline/Services/Token/JwtUserTokenBadFormatException.cs +++ b/BackEnd/Timeline/Services/Token/JwtUserTokenBadFormatException.cs @@ -1,6 +1,5 @@ using System; using System.Globalization; -using static Timeline.Resources.Services.Exception; namespace Timeline.Services.Token { @@ -34,16 +33,15 @@ namespace Timeline.Services.Token { var reason = type switch { - ErrorKind.NoIdClaim => JwtUserTokenBadFormatExceptionIdMissing, - ErrorKind.IdClaimBadFormat => JwtUserTokenBadFormatExceptionIdBadFormat, - ErrorKind.NoVersionClaim => JwtUserTokenBadFormatExceptionVersionMissing, - ErrorKind.VersionClaimBadFormat => JwtUserTokenBadFormatExceptionVersionBadFormat, - ErrorKind.Other => JwtUserTokenBadFormatExceptionOthers, - _ => JwtUserTokenBadFormatExceptionUnknown + ErrorKind.NoIdClaim => Resource.ExceptionJwtUserTokenBadFormatReasonIdMissing, + ErrorKind.IdClaimBadFormat => Resource.ExceptionJwtUserTokenBadFormatReasonIdBadFormat, + ErrorKind.NoVersionClaim => Resource.ExceptionJwtUserTokenBadFormatReasonVersionMissing, + ErrorKind.VersionClaimBadFormat => Resource.ExceptionJwtUserTokenBadFormatReasonVersionBadFormat, + ErrorKind.Other => Resource.ExceptionJwtUserTokenBadFormatReasonOthers, + _ => Resource.ExceptionJwtUserTokenBadFormatReasonUnknown }; - return string.Format(CultureInfo.CurrentCulture, - Resources.Services.Exception.JwtUserTokenBadFormatException, reason); + return string.Format(CultureInfo.CurrentCulture, Resource.ExceptionJwtUserTokenBadFormat, reason); } } } diff --git a/BackEnd/Timeline/Services/Token/Resource.Designer.cs b/BackEnd/Timeline/Services/Token/Resource.Designer.cs new file mode 100644 index 00000000..4321c665 --- /dev/null +++ b/BackEnd/Timeline/Services/Token/Resource.Designer.cs @@ -0,0 +1,162 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Timeline.Services.Token { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resource { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resource() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Services.Token.Resource", typeof(Resource).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to The token didn't pass verification because {0}.. + /// + internal static string ExceptionJwtUserTokenBadFormat { + get { + return ResourceManager.GetString("ExceptionJwtUserTokenBadFormat", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to id claim is not a number. + /// + internal static string ExceptionJwtUserTokenBadFormatReasonIdBadFormat { + get { + return ResourceManager.GetString("ExceptionJwtUserTokenBadFormatReasonIdBadFormat", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to id claim does not exist. + /// + internal static string ExceptionJwtUserTokenBadFormatReasonIdMissing { + get { + return ResourceManager.GetString("ExceptionJwtUserTokenBadFormatReasonIdMissing", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to other error, see inner exception for information. + /// + internal static string ExceptionJwtUserTokenBadFormatReasonOthers { + get { + return ResourceManager.GetString("ExceptionJwtUserTokenBadFormatReasonOthers", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to unknown error. + /// + internal static string ExceptionJwtUserTokenBadFormatReasonUnknown { + get { + return ResourceManager.GetString("ExceptionJwtUserTokenBadFormatReasonUnknown", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to version claim is not a number.. + /// + internal static string ExceptionJwtUserTokenBadFormatReasonVersionBadFormat { + get { + return ResourceManager.GetString("ExceptionJwtUserTokenBadFormatReasonVersionBadFormat", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to version claim does not exist.. + /// + internal static string ExceptionJwtUserTokenBadFormatReasonVersionMissing { + get { + return ResourceManager.GetString("ExceptionJwtUserTokenBadFormatReasonVersionMissing", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The token is of bad format, which means it may not be created by the server.. + /// + internal static string ExceptionUserTokenBadFormat { + get { + return ResourceManager.GetString("ExceptionUserTokenBadFormat", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The token is expired because its expiration time has passed.. + /// + internal static string ExceptionUserTokenTimeExpired { + get { + return ResourceManager.GetString("ExceptionUserTokenTimeExpired", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The owner user of the token does not exist.. + /// + internal static string ExceptionUserTokenUserNotExist { + get { + return ResourceManager.GetString("ExceptionUserTokenUserNotExist", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The token is of bad version.. + /// + internal static string ExceptionUserTokenVersionExpired { + get { + return ResourceManager.GetString("ExceptionUserTokenVersionExpired", resourceCulture); + } + } + } +} diff --git a/BackEnd/Timeline/Services/Token/Resource.resx b/BackEnd/Timeline/Services/Token/Resource.resx new file mode 100644 index 00000000..c42da2ca --- /dev/null +++ b/BackEnd/Timeline/Services/Token/Resource.resx @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + The token didn't pass verification because {0}. + + + id claim is not a number + + + id claim does not exist + + + other error, see inner exception for information + + + unknown error + + + version claim is not a number. + + + version claim does not exist. + + + The token is of bad format, which means it may not be created by the server. + + + The token is expired because its expiration time has passed. + + + The owner user of the token does not exist. + + + The token is of bad version. + + \ No newline at end of file diff --git a/BackEnd/Timeline/Services/Token/UserTokenException.cs b/BackEnd/Timeline/Services/Token/UserTokenException.cs index d666ba10..a781eb05 100644 --- a/BackEnd/Timeline/Services/Token/UserTokenException.cs +++ b/BackEnd/Timeline/Services/Token/UserTokenException.cs @@ -2,7 +2,6 @@ namespace Timeline.Services.Token { - [Serializable] public class UserTokenException : Exception { @@ -22,11 +21,11 @@ namespace Timeline.Services.Token [Serializable] public class UserTokenTimeExpiredException : UserTokenException { - public UserTokenTimeExpiredException() : base(Resources.Services.Exception.UserTokenTimeExpireException) { } + public UserTokenTimeExpiredException() : base(Resource.ExceptionUserTokenTimeExpired) { } public UserTokenTimeExpiredException(string message) : base(message) { } public UserTokenTimeExpiredException(string message, Exception inner) : base(message, inner) { } - public UserTokenTimeExpiredException(string token, DateTime expireTime, DateTime verifyTime) : base(token, Resources.Services.Exception.UserTokenTimeExpireException) { ExpireTime = expireTime; VerifyTime = verifyTime; } - public UserTokenTimeExpiredException(string token, DateTime expireTime, DateTime verifyTime, Exception inner) : base(token, Resources.Services.Exception.UserTokenTimeExpireException, inner) { ExpireTime = expireTime; VerifyTime = verifyTime; } + public UserTokenTimeExpiredException(string token, DateTime expireTime, DateTime verifyTime) : base(token, Resource.ExceptionUserTokenTimeExpired) { ExpireTime = expireTime; VerifyTime = verifyTime; } + public UserTokenTimeExpiredException(string token, DateTime expireTime, DateTime verifyTime, Exception inner) : base(token, Resource.ExceptionUserTokenTimeExpired, inner) { ExpireTime = expireTime; VerifyTime = verifyTime; } protected UserTokenTimeExpiredException( System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } @@ -39,11 +38,11 @@ namespace Timeline.Services.Token [Serializable] public class UserTokenVersionExpiredException : UserTokenException { - public UserTokenVersionExpiredException() : base(Resources.Services.Exception.UserTokenBadVersionException) { } + public UserTokenVersionExpiredException() : base(Resource.ExceptionUserTokenVersionExpired) { } public UserTokenVersionExpiredException(string message) : base(message) { } public UserTokenVersionExpiredException(string message, Exception inner) : base(message, inner) { } - public UserTokenVersionExpiredException(string token, long tokenVersion, long requiredVersion) : base(token, Resources.Services.Exception.UserTokenBadVersionException) { TokenVersion = tokenVersion; RequiredVersion = requiredVersion; } - public UserTokenVersionExpiredException(string token, long tokenVersion, long requiredVersion, Exception inner) : base(token, Resources.Services.Exception.UserTokenBadVersionException, inner) { TokenVersion = tokenVersion; RequiredVersion = requiredVersion; } + public UserTokenVersionExpiredException(string token, long tokenVersion, long requiredVersion) : base(token, Resource.ExceptionUserTokenVersionExpired) { TokenVersion = tokenVersion; RequiredVersion = requiredVersion; } + public UserTokenVersionExpiredException(string token, long tokenVersion, long requiredVersion, Exception inner) : base(token, Resource.ExceptionUserTokenVersionExpired, inner) { TokenVersion = tokenVersion; RequiredVersion = requiredVersion; } protected UserTokenVersionExpiredException( System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } @@ -57,11 +56,9 @@ namespace Timeline.Services.Token [Serializable] public class UserTokenUserNotExistException : UserTokenException { - const string message = "The owner of the token does not exist."; - - public UserTokenUserNotExistException() : base(message) { } - public UserTokenUserNotExistException(string token) : base(token, message) { } - public UserTokenUserNotExistException(string token, Exception inner) : base(token, message, inner) { } + public UserTokenUserNotExistException() : base(Resource.ExceptionUserTokenUserNotExist) { } + public UserTokenUserNotExistException(string token) : base(token, Resource.ExceptionUserTokenUserNotExist) { } + public UserTokenUserNotExistException(string token, Exception inner) : base(token, Resource.ExceptionUserTokenUserNotExist, inner) { } protected UserTokenUserNotExistException( System.Runtime.Serialization.SerializationInfo info, @@ -71,10 +68,10 @@ namespace Timeline.Services.Token [Serializable] public class UserTokenBadFormatException : UserTokenException { - public UserTokenBadFormatException() : base(Resources.Services.Exception.UserTokenBadFormatException) { } - public UserTokenBadFormatException(string token) : base(token, Resources.Services.Exception.UserTokenBadFormatException) { } + public UserTokenBadFormatException() : base(Resource.ExceptionUserTokenBadFormat) { } + public UserTokenBadFormatException(string token) : base(token, Resource.ExceptionUserTokenBadFormat) { } public UserTokenBadFormatException(string token, string message) : base(token, message) { } - public UserTokenBadFormatException(string token, Exception inner) : base(token, Resources.Services.Exception.UserTokenBadFormatException, inner) { } + public UserTokenBadFormatException(string token, Exception inner) : base(token, Resource.ExceptionUserTokenBadFormat, inner) { } public UserTokenBadFormatException(string token, string message, Exception inner) : base(token, message, inner) { } protected UserTokenBadFormatException( System.Runtime.Serialization.SerializationInfo info, diff --git a/BackEnd/Timeline/Services/User/PasswordBadFormatException.cs b/BackEnd/Timeline/Services/User/PasswordBadFormatException.cs deleted file mode 100644 index b9d76017..00000000 --- a/BackEnd/Timeline/Services/User/PasswordBadFormatException.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; - -namespace Timeline.Services.User -{ - [Serializable] - public class PasswordBadFormatException : Exception - { - public PasswordBadFormatException() : base(Resources.Services.Exception.PasswordBadFormatException) { } - public PasswordBadFormatException(string message) : base(message) { } - public PasswordBadFormatException(string message, Exception inner) : base(message, inner) { } - - public PasswordBadFormatException(string password, string validationMessage) : this() - { - Password = password; - ValidationMessage = validationMessage; - } - - protected PasswordBadFormatException( - System.Runtime.Serialization.SerializationInfo info, - System.Runtime.Serialization.StreamingContext context) : base(info, context) { } - - public string Password { get; set; } = ""; - - public string ValidationMessage { get; set; } = ""; - } -} diff --git a/BackEnd/Timeline/Services/User/PasswordService.cs b/BackEnd/Timeline/Services/User/PasswordService.cs index 580471e1..1c14875f 100644 --- a/BackEnd/Timeline/Services/User/PasswordService.cs +++ b/BackEnd/Timeline/Services/User/PasswordService.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Cryptography.KeyDerivation; using System; +using System.Globalization; using System.Runtime.CompilerServices; using System.Security.Cryptography; @@ -12,18 +13,13 @@ namespace Timeline.Services.User [Serializable] public class HashedPasswordBadFromatException : Exception { - private static string MakeMessage(string reason) - { - return Resources.Services.Exception.HashedPasswordBadFromatException + " Reason: " + reason; - } - - public HashedPasswordBadFromatException() : base(Resources.Services.Exception.HashedPasswordBadFromatException) { } + public HashedPasswordBadFromatException() : base(Resource.ExceptionHashedPasswordBadFormat) { } public HashedPasswordBadFromatException(string message) : base(message) { } public HashedPasswordBadFromatException(string message, Exception inner) : base(message, inner) { } - public HashedPasswordBadFromatException(string hashedPassword, string reason) : base(MakeMessage(reason)) { HashedPassword = hashedPassword; } - public HashedPasswordBadFromatException(string hashedPassword, string reason, Exception inner) : base(MakeMessage(reason), inner) { HashedPassword = hashedPassword; } + public HashedPasswordBadFromatException(string hashedPassword, string reason, Exception? inner = null) + : base(string.Format(CultureInfo.InvariantCulture, Resource.ExceptionHashedPasswordBadFormat, reason), inner) { HashedPassword = hashedPassword; } protected HashedPasswordBadFromatException( System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } @@ -150,19 +146,19 @@ namespace Timeline.Services.User } catch (FormatException e) { - throw new HashedPasswordBadFromatException(hashedPassword, Resources.Services.Exception.HashedPasswordBadFromatExceptionNotBase64, e); + throw new HashedPasswordBadFromatException(hashedPassword, Resource.ExceptionHashedPasswordBadFormatReasonNotBase64, e); } // read the format marker from the hashed password if (decodedHashedPassword.Length == 0) { - throw new HashedPasswordBadFromatException(hashedPassword, Resources.Services.Exception.HashedPasswordBadFromatExceptionNotLength0); + throw new HashedPasswordBadFromatException(hashedPassword, Resource.ExceptionHashedPasswordBadFormatReasonLength0); } return (decodedHashedPassword[0]) switch { 0x01 => VerifyHashedPasswordV3(decodedHashedPassword, providedPassword, hashedPassword), - _ => throw new HashedPasswordBadFromatException(hashedPassword, Resources.Services.Exception.HashedPasswordBadFromatExceptionNotUnknownMarker), + _ => throw new HashedPasswordBadFromatException(hashedPassword, Resource.ExceptionHashedPasswordBadFormatReasonUnknownMarker), }; } @@ -178,7 +174,7 @@ namespace Timeline.Services.User // Read the salt: must be >= 128 bits if (saltLength < 128 / 8) { - throw new HashedPasswordBadFromatException(hashedPasswordString, Resources.Services.Exception.HashedPasswordBadFromatExceptionNotSaltTooShort); + throw new HashedPasswordBadFromatException(hashedPasswordString, Resource.ExceptionHashedPasswordBadFormatReasonSaltTooShort); } byte[] salt = new byte[saltLength]; Buffer.BlockCopy(hashedPassword, 13, salt, 0, salt.Length); @@ -187,7 +183,7 @@ namespace Timeline.Services.User int subkeyLength = hashedPassword.Length - 13 - salt.Length; if (subkeyLength < 128 / 8) { - throw new HashedPasswordBadFromatException(hashedPasswordString, Resources.Services.Exception.HashedPasswordBadFromatExceptionNotSubkeyTooShort); + throw new HashedPasswordBadFromatException(hashedPasswordString, Resource.ExceptionHashedPasswordBadFormatReasonSubkeyTooShort); } byte[] expectedSubkey = new byte[subkeyLength]; Buffer.BlockCopy(hashedPassword, 13 + salt.Length, expectedSubkey, 0, expectedSubkey.Length); @@ -201,7 +197,7 @@ namespace Timeline.Services.User // This should never occur except in the case of a malformed payload, where // we might go off the end of the array. Regardless, a malformed payload // implies verification failed. - throw new HashedPasswordBadFromatException(hashedPasswordString, Resources.Services.Exception.HashedPasswordBadFromatExceptionNotOthers, e); + throw new HashedPasswordBadFromatException(hashedPasswordString, Resource.ExceptionHashedPasswordBadFormatReasonOthers, e); } } diff --git a/BackEnd/Timeline/Services/User/Resource.Designer.cs b/BackEnd/Timeline/Services/User/Resource.Designer.cs index d64a7aab..4f75b055 100644 --- a/BackEnd/Timeline/Services/User/Resource.Designer.cs +++ b/BackEnd/Timeline/Services/User/Resource.Designer.cs @@ -69,6 +69,69 @@ namespace Timeline.Services.User { } } + /// + /// Looks up a localized string similar to The hashes password is of bad format. It might not be created by server. Reason: {0}. + /// + internal static string ExceptionHashedPasswordBadFormat { + get { + return ResourceManager.GetString("ExceptionHashedPasswordBadFormat", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Decoded hashed password is of length 0.. + /// + internal static string ExceptionHashedPasswordBadFormatReasonLength0 { + get { + return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonLength0", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Not of valid base64 format. See inner exception.. + /// + internal static string ExceptionHashedPasswordBadFormatReasonNotBase64 { + get { + return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonNotBase64", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to See inner exception.. + /// + internal static string ExceptionHashedPasswordBadFormatReasonOthers { + get { + return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonOthers", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Salt length < 128 bits.. + /// + internal static string ExceptionHashedPasswordBadFormatReasonSaltTooShort { + get { + return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonSaltTooShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Subkey length < 128 bits.. + /// + internal static string ExceptionHashedPasswordBadFormatReasonSubkeyTooShort { + get { + return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonSubkeyTooShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Unknown format marker.. + /// + internal static string ExceptionHashedPasswordBadFormatReasonUnknownMarker { + get { + return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonUnknownMarker", resourceCulture); + } + } + /// /// Looks up a localized string similar to Nickname is of bad format. {0}. /// diff --git a/BackEnd/Timeline/Services/User/Resource.resx b/BackEnd/Timeline/Services/User/Resource.resx index 732cfefd..28e75b19 100644 --- a/BackEnd/Timeline/Services/User/Resource.resx +++ b/BackEnd/Timeline/Services/User/Resource.resx @@ -120,6 +120,27 @@ Password is wrong. + + The hashes password is of bad format. It might not be created by server. Reason: {0} + + + Decoded hashed password is of length 0. + + + Not of valid base64 format. See inner exception. + + + See inner exception. + + + Salt length < 128 bits. + + + Subkey length < 128 bits. + + + Unknown format marker. + Nickname is of bad format. {0} diff --git a/BackEnd/Timeline/Timeline.csproj b/BackEnd/Timeline/Timeline.csproj index 45e20df5..c1786488 100644 --- a/BackEnd/Timeline/Timeline.csproj +++ b/BackEnd/Timeline/Timeline.csproj @@ -128,11 +128,6 @@ True DataManager.resx - - True - True - Exception.resx - True True @@ -173,6 +168,11 @@ True Resource.resx + + True + True + Resource.resx + True True @@ -246,10 +246,6 @@ ResXFileCodeGenerator DataManager.Designer.cs - - ResXFileCodeGenerator - Exception.Designer.cs - ResXFileCodeGenerator Exceptions.Designer.cs @@ -282,6 +278,10 @@ ResXFileCodeGenerator Resource.Designer.cs + + ResXFileCodeGenerator + Resource.Designer.cs + ResXFileCodeGenerator Resource.Designer.cs -- cgit v1.2.3