diff options
author | crupest <crupest@outlook.com> | 2021-04-25 21:37:52 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-04-25 21:37:52 +0800 |
commit | dc4f255e0fab5f6b39b7add197830591b89103c0 (patch) | |
tree | e919eaa01fda4efe318e48829360eeef7bf6491a /BackEnd | |
parent | 657fb589137099794e58fbd35beb7d942b376965 (diff) | |
download | timeline-dc4f255e0fab5f6b39b7add197830591b89103c0.tar.gz timeline-dc4f255e0fab5f6b39b7add197830591b89103c0.tar.bz2 timeline-dc4f255e0fab5f6b39b7add197830591b89103c0.zip |
...
Diffstat (limited to 'BackEnd')
-rw-r--r-- | BackEnd/Timeline/Resources/Services/Exception.Designer.cs | 234 | ||||
-rw-r--r-- | BackEnd/Timeline/Services/Token/JwtUserTokenBadFormatException.cs | 16 | ||||
-rw-r--r-- | BackEnd/Timeline/Services/Token/Resource.Designer.cs | 162 | ||||
-rw-r--r-- | BackEnd/Timeline/Services/Token/Resource.resx (renamed from BackEnd/Timeline/Resources/Services/Exception.resx) | 54 | ||||
-rw-r--r-- | BackEnd/Timeline/Services/Token/UserTokenException.cs | 27 | ||||
-rw-r--r-- | BackEnd/Timeline/Services/User/PasswordBadFormatException.cs | 26 | ||||
-rw-r--r-- | BackEnd/Timeline/Services/User/PasswordService.cs | 24 | ||||
-rw-r--r-- | BackEnd/Timeline/Services/User/Resource.Designer.cs | 63 | ||||
-rw-r--r-- | BackEnd/Timeline/Services/User/Resource.resx | 21 | ||||
-rw-r--r-- | BackEnd/Timeline/Timeline.csproj | 18 |
10 files changed, 299 insertions, 346 deletions
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 @@ -//------------------------------------------------------------------------------
-// <auto-generated>
-// 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.
-// </auto-generated>
-//------------------------------------------------------------------------------
-
-namespace Timeline.Resources.Services {
- using System;
-
-
- /// <summary>
- /// A strongly-typed resource class, for looking up localized strings, etc.
- /// </summary>
- // 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() {
- }
-
- /// <summary>
- /// Returns the cached ResourceManager instance used by this class.
- /// </summary>
- [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;
- }
- }
-
- /// <summary>
- /// Overrides the current thread's CurrentUICulture property for all
- /// resource lookups using this strongly typed resource class.
- /// </summary>
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture {
- get {
- return resourceCulture;
- }
- set {
- resourceCulture = value;
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The password is wrong..
- /// </summary>
- internal static string BadPasswordException {
- get {
- return ResourceManager.GetString("BadPasswordException", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The hashes password is of bad format. It might not be created by server..
- /// </summary>
- internal static string HashedPasswordBadFromatException {
- get {
- return ResourceManager.GetString("HashedPasswordBadFromatException", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Not of valid base64 format. See inner exception..
- /// </summary>
- internal static string HashedPasswordBadFromatExceptionNotBase64 {
- get {
- return ResourceManager.GetString("HashedPasswordBadFromatExceptionNotBase64", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Decoded hashed password is of length 0..
- /// </summary>
- internal static string HashedPasswordBadFromatExceptionNotLength0 {
- get {
- return ResourceManager.GetString("HashedPasswordBadFromatExceptionNotLength0", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to See inner exception..
- /// </summary>
- internal static string HashedPasswordBadFromatExceptionNotOthers {
- get {
- return ResourceManager.GetString("HashedPasswordBadFromatExceptionNotOthers", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Salt length < 128 bits..
- /// </summary>
- internal static string HashedPasswordBadFromatExceptionNotSaltTooShort {
- get {
- return ResourceManager.GetString("HashedPasswordBadFromatExceptionNotSaltTooShort", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Subkey length < 128 bits..
- /// </summary>
- internal static string HashedPasswordBadFromatExceptionNotSubkeyTooShort {
- get {
- return ResourceManager.GetString("HashedPasswordBadFromatExceptionNotSubkeyTooShort", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Unknown format marker..
- /// </summary>
- internal static string HashedPasswordBadFromatExceptionNotUnknownMarker {
- get {
- return ResourceManager.GetString("HashedPasswordBadFromatExceptionNotUnknownMarker", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The token didn't pass verification because {0}..
- /// </summary>
- internal static string JwtUserTokenBadFormatException {
- get {
- return ResourceManager.GetString("JwtUserTokenBadFormatException", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to id claim is not a number.
- /// </summary>
- internal static string JwtUserTokenBadFormatExceptionIdBadFormat {
- get {
- return ResourceManager.GetString("JwtUserTokenBadFormatExceptionIdBadFormat", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to id claim does not exist.
- /// </summary>
- internal static string JwtUserTokenBadFormatExceptionIdMissing {
- get {
- return ResourceManager.GetString("JwtUserTokenBadFormatExceptionIdMissing", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to other error, see inner exception for information.
- /// </summary>
- internal static string JwtUserTokenBadFormatExceptionOthers {
- get {
- return ResourceManager.GetString("JwtUserTokenBadFormatExceptionOthers", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to unknown error.
- /// </summary>
- internal static string JwtUserTokenBadFormatExceptionUnknown {
- get {
- return ResourceManager.GetString("JwtUserTokenBadFormatExceptionUnknown", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to version claim is not a number..
- /// </summary>
- internal static string JwtUserTokenBadFormatExceptionVersionBadFormat {
- get {
- return ResourceManager.GetString("JwtUserTokenBadFormatExceptionVersionBadFormat", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to version claim does not exist..
- /// </summary>
- internal static string JwtUserTokenBadFormatExceptionVersionMissing {
- get {
- return ResourceManager.GetString("JwtUserTokenBadFormatExceptionVersionMissing", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Password is of bad format..
- /// </summary>
- internal static string PasswordBadFormatException {
- get {
- return ResourceManager.GetString("PasswordBadFormatException", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The token is of bad format, which means it may not be created by the server..
- /// </summary>
- internal static string UserTokenBadFormatException {
- get {
- return ResourceManager.GetString("UserTokenBadFormatException", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The token is of bad version..
- /// </summary>
- internal static string UserTokenBadVersionException {
- get {
- return ResourceManager.GetString("UserTokenBadVersionException", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The token is expired because its expiration time has passed..
- /// </summary>
- internal static string UserTokenTimeExpireException {
- get {
- return ResourceManager.GetString("UserTokenTimeExpireException", resourceCulture);
- }
- }
- }
-}
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 @@ +//------------------------------------------------------------------------------
+// <auto-generated>
+// 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.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Timeline.Services.Token {
+ using System;
+
+
+ /// <summary>
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ /// </summary>
+ // 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() {
+ }
+
+ /// <summary>
+ /// Returns the cached ResourceManager instance used by this class.
+ /// </summary>
+ [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;
+ }
+ }
+
+ /// <summary>
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to The token didn't pass verification because {0}..
+ /// </summary>
+ internal static string ExceptionJwtUserTokenBadFormat {
+ get {
+ return ResourceManager.GetString("ExceptionJwtUserTokenBadFormat", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to id claim is not a number.
+ /// </summary>
+ internal static string ExceptionJwtUserTokenBadFormatReasonIdBadFormat {
+ get {
+ return ResourceManager.GetString("ExceptionJwtUserTokenBadFormatReasonIdBadFormat", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to id claim does not exist.
+ /// </summary>
+ internal static string ExceptionJwtUserTokenBadFormatReasonIdMissing {
+ get {
+ return ResourceManager.GetString("ExceptionJwtUserTokenBadFormatReasonIdMissing", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to other error, see inner exception for information.
+ /// </summary>
+ internal static string ExceptionJwtUserTokenBadFormatReasonOthers {
+ get {
+ return ResourceManager.GetString("ExceptionJwtUserTokenBadFormatReasonOthers", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to unknown error.
+ /// </summary>
+ internal static string ExceptionJwtUserTokenBadFormatReasonUnknown {
+ get {
+ return ResourceManager.GetString("ExceptionJwtUserTokenBadFormatReasonUnknown", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to version claim is not a number..
+ /// </summary>
+ internal static string ExceptionJwtUserTokenBadFormatReasonVersionBadFormat {
+ get {
+ return ResourceManager.GetString("ExceptionJwtUserTokenBadFormatReasonVersionBadFormat", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to version claim does not exist..
+ /// </summary>
+ internal static string ExceptionJwtUserTokenBadFormatReasonVersionMissing {
+ get {
+ return ResourceManager.GetString("ExceptionJwtUserTokenBadFormatReasonVersionMissing", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to The token is of bad format, which means it may not be created by the server..
+ /// </summary>
+ internal static string ExceptionUserTokenBadFormat {
+ get {
+ return ResourceManager.GetString("ExceptionUserTokenBadFormat", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to The token is expired because its expiration time has passed..
+ /// </summary>
+ internal static string ExceptionUserTokenTimeExpired {
+ get {
+ return ResourceManager.GetString("ExceptionUserTokenTimeExpired", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to The owner user of the token does not exist..
+ /// </summary>
+ internal static string ExceptionUserTokenUserNotExist {
+ get {
+ return ResourceManager.GetString("ExceptionUserTokenUserNotExist", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to The token is of bad version..
+ /// </summary>
+ internal static string ExceptionUserTokenVersionExpired {
+ get {
+ return ResourceManager.GetString("ExceptionUserTokenVersionExpired", resourceCulture);
+ }
+ }
+ }
+}
diff --git a/BackEnd/Timeline/Resources/Services/Exception.resx b/BackEnd/Timeline/Services/Token/Resource.resx index c31ed7c7..c42da2ca 100644 --- a/BackEnd/Timeline/Resources/Services/Exception.resx +++ b/BackEnd/Timeline/Services/Token/Resource.resx @@ -117,61 +117,37 @@ <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
- <data name="BadPasswordException" xml:space="preserve">
- <value>The password is wrong.</value>
- </data>
- <data name="HashedPasswordBadFromatException" xml:space="preserve">
- <value>The hashes password is of bad format. It might not be created by server.</value>
- </data>
- <data name="HashedPasswordBadFromatExceptionNotBase64" xml:space="preserve">
- <value>Not of valid base64 format. See inner exception.</value>
- </data>
- <data name="HashedPasswordBadFromatExceptionNotLength0" xml:space="preserve">
- <value>Decoded hashed password is of length 0.</value>
- </data>
- <data name="HashedPasswordBadFromatExceptionNotOthers" xml:space="preserve">
- <value>See inner exception.</value>
- </data>
- <data name="HashedPasswordBadFromatExceptionNotSaltTooShort" xml:space="preserve">
- <value>Salt length < 128 bits.</value>
- </data>
- <data name="HashedPasswordBadFromatExceptionNotSubkeyTooShort" xml:space="preserve">
- <value>Subkey length < 128 bits.</value>
- </data>
- <data name="HashedPasswordBadFromatExceptionNotUnknownMarker" xml:space="preserve">
- <value>Unknown format marker.</value>
- </data>
- <data name="JwtUserTokenBadFormatException" xml:space="preserve">
+ <data name="ExceptionJwtUserTokenBadFormat" xml:space="preserve">
<value>The token didn't pass verification because {0}.</value>
</data>
- <data name="JwtUserTokenBadFormatExceptionIdBadFormat" xml:space="preserve">
+ <data name="ExceptionJwtUserTokenBadFormatReasonIdBadFormat" xml:space="preserve">
<value>id claim is not a number</value>
</data>
- <data name="JwtUserTokenBadFormatExceptionIdMissing" xml:space="preserve">
+ <data name="ExceptionJwtUserTokenBadFormatReasonIdMissing" xml:space="preserve">
<value>id claim does not exist</value>
</data>
- <data name="JwtUserTokenBadFormatExceptionOthers" xml:space="preserve">
+ <data name="ExceptionJwtUserTokenBadFormatReasonOthers" xml:space="preserve">
<value>other error, see inner exception for information</value>
</data>
- <data name="JwtUserTokenBadFormatExceptionUnknown" xml:space="preserve">
+ <data name="ExceptionJwtUserTokenBadFormatReasonUnknown" xml:space="preserve">
<value>unknown error</value>
</data>
- <data name="JwtUserTokenBadFormatExceptionVersionBadFormat" xml:space="preserve">
+ <data name="ExceptionJwtUserTokenBadFormatReasonVersionBadFormat" xml:space="preserve">
<value>version claim is not a number.</value>
</data>
- <data name="JwtUserTokenBadFormatExceptionVersionMissing" xml:space="preserve">
+ <data name="ExceptionJwtUserTokenBadFormatReasonVersionMissing" xml:space="preserve">
<value>version claim does not exist.</value>
</data>
- <data name="PasswordBadFormatException" xml:space="preserve">
- <value>Password is of bad format.</value>
- </data>
- <data name="UserTokenBadFormatException" xml:space="preserve">
+ <data name="ExceptionUserTokenBadFormat" xml:space="preserve">
<value>The token is of bad format, which means it may not be created by the server.</value>
</data>
- <data name="UserTokenBadVersionException" xml:space="preserve">
- <value>The token is of bad version.</value>
- </data>
- <data name="UserTokenTimeExpireException" xml:space="preserve">
+ <data name="ExceptionUserTokenTimeExpired" xml:space="preserve">
<value>The token is expired because its expiration time has passed.</value>
</data>
+ <data name="ExceptionUserTokenUserNotExist" xml:space="preserve">
+ <value>The owner user of the token does not exist.</value>
+ </data>
+ <data name="ExceptionUserTokenVersionExpired" xml:space="preserve">
+ <value>The token is of bad version.</value>
+ </data>
</root>
\ 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 @@ -70,6 +70,69 @@ namespace Timeline.Services.User { }
/// <summary>
+ /// Looks up a localized string similar to The hashes password is of bad format. It might not be created by server. Reason: {0}.
+ /// </summary>
+ internal static string ExceptionHashedPasswordBadFormat {
+ get {
+ return ResourceManager.GetString("ExceptionHashedPasswordBadFormat", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Decoded hashed password is of length 0..
+ /// </summary>
+ internal static string ExceptionHashedPasswordBadFormatReasonLength0 {
+ get {
+ return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonLength0", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Not of valid base64 format. See inner exception..
+ /// </summary>
+ internal static string ExceptionHashedPasswordBadFormatReasonNotBase64 {
+ get {
+ return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonNotBase64", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to See inner exception..
+ /// </summary>
+ internal static string ExceptionHashedPasswordBadFormatReasonOthers {
+ get {
+ return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonOthers", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Salt length < 128 bits..
+ /// </summary>
+ internal static string ExceptionHashedPasswordBadFormatReasonSaltTooShort {
+ get {
+ return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonSaltTooShort", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Subkey length < 128 bits..
+ /// </summary>
+ internal static string ExceptionHashedPasswordBadFormatReasonSubkeyTooShort {
+ get {
+ return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonSubkeyTooShort", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Unknown format marker..
+ /// </summary>
+ internal static string ExceptionHashedPasswordBadFormatReasonUnknownMarker {
+ get {
+ return ResourceManager.GetString("ExceptionHashedPasswordBadFormatReasonUnknownMarker", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Nickname is of bad format. {0}.
/// </summary>
internal static string ExceptionNicknameBadFormat {
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 @@ <data name="ExceptionBadPassword" xml:space="preserve">
<value>Password is wrong.</value>
</data>
+ <data name="ExceptionHashedPasswordBadFormat" xml:space="preserve">
+ <value>The hashes password is of bad format. It might not be created by server. Reason: {0}</value>
+ </data>
+ <data name="ExceptionHashedPasswordBadFormatReasonLength0" xml:space="preserve">
+ <value>Decoded hashed password is of length 0.</value>
+ </data>
+ <data name="ExceptionHashedPasswordBadFormatReasonNotBase64" xml:space="preserve">
+ <value>Not of valid base64 format. See inner exception.</value>
+ </data>
+ <data name="ExceptionHashedPasswordBadFormatReasonOthers" xml:space="preserve">
+ <value>See inner exception.</value>
+ </data>
+ <data name="ExceptionHashedPasswordBadFormatReasonSaltTooShort" xml:space="preserve">
+ <value>Salt length < 128 bits.</value>
+ </data>
+ <data name="ExceptionHashedPasswordBadFormatReasonSubkeyTooShort" xml:space="preserve">
+ <value>Subkey length < 128 bits.</value>
+ </data>
+ <data name="ExceptionHashedPasswordBadFormatReasonUnknownMarker" xml:space="preserve">
+ <value>Unknown format marker.</value>
+ </data>
<data name="ExceptionNicknameBadFormat" xml:space="preserve">
<value>Nickname is of bad format. {0}</value>
</data>
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 @@ <AutoGen>True</AutoGen>
<DependentUpon>DataManager.resx</DependentUpon>
</Compile>
- <Compile Update="Resources\Services\Exception.Designer.cs">
- <DesignTime>True</DesignTime>
- <AutoGen>True</AutoGen>
- <DependentUpon>Exception.resx</DependentUpon>
- </Compile>
<Compile Update="Resources\Services\Exceptions.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
@@ -173,6 +168,11 @@ <AutoGen>True</AutoGen>
<DependentUpon>Resource.resx</DependentUpon>
</Compile>
+ <Compile Update="Services\Token\Resource.Designer.cs">
+ <DesignTime>True</DesignTime>
+ <AutoGen>True</AutoGen>
+ <DependentUpon>Resource.resx</DependentUpon>
+ </Compile>
<Compile Update="Services\User\Resource.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
@@ -246,10 +246,6 @@ <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>DataManager.Designer.cs</LastGenOutput>
</EmbeddedResource>
- <EmbeddedResource Update="Resources\Services\Exception.resx">
- <Generator>ResXFileCodeGenerator</Generator>
- <LastGenOutput>Exception.Designer.cs</LastGenOutput>
- </EmbeddedResource>
<EmbeddedResource Update="Resources\Services\Exceptions.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Exceptions.Designer.cs</LastGenOutput>
@@ -282,6 +278,10 @@ <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
</EmbeddedResource>
+ <EmbeddedResource Update="Services\Token\Resource.resx">
+ <Generator>ResXFileCodeGenerator</Generator>
+ <LastGenOutput>Resource.Designer.cs</LastGenOutput>
+ </EmbeddedResource>
<EmbeddedResource Update="Services\User\Resource.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
|