diff options
| author | Phallacy <Dragoonmac@gmail.com> | 2019-02-18 01:26:01 -0800 |
|---|---|---|
| committer | Phallacy <Dragoonmac@gmail.com> | 2019-02-18 01:26:01 -0800 |
| commit | 48e7274d3783e57f89f6e1cc76fcd8696e987ec5 (patch) | |
| tree | 8c4fe049728082d18f3f3ca8b4dd9c54c79a3e50 /MediaBrowser.Model/Cryptography/PasswordHash.cs | |
| parent | 9f3aa2cead95ec0a66a518919c179eea4cad5d9c (diff) | |
added justaman notes, fixed new bug from emty has removals
Diffstat (limited to 'MediaBrowser.Model/Cryptography/PasswordHash.cs')
| -rw-r--r-- | MediaBrowser.Model/Cryptography/PasswordHash.cs | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/MediaBrowser.Model/Cryptography/PasswordHash.cs b/MediaBrowser.Model/Cryptography/PasswordHash.cs index cd61657c1..3a817543b 100644 --- a/MediaBrowser.Model/Cryptography/PasswordHash.cs +++ b/MediaBrowser.Model/Cryptography/PasswordHash.cs @@ -18,48 +18,52 @@ namespace MediaBrowser.Model.Cryptography public byte[] HashBytes;
public PasswordHash(string storageString)
{
- string[] SplitStorageString = storageString.Split('$');
- Id = SplitStorageString[1];
- if (SplitStorageString[2].Contains("="))
+ string[] splitted = storageString.Split('$');
+ Id = splitted[1];
+ if (splitted[2].Contains("="))
{
- foreach (string paramset in (SplitStorageString[2].Split(',')))
+ foreach (string paramset in (splitted[2].Split(',')))
{
if (!String.IsNullOrEmpty(paramset))
{
string[] fields = paramset.Split('='); - if(fields.Length == 2) + if (fields.Length == 2) { Parameters.Add(fields[0], fields[1]); + } + else + { + throw new Exception($"Malformed parameter in password hash string {paramset}"); }
}
}
- if (SplitStorageString.Length == 5)
+ if (splitted.Length == 5)
{
- Salt = SplitStorageString[3];
+ Salt = splitted[3];
SaltBytes = ConvertFromByteString(Salt);
- Hash = SplitStorageString[4];
+ Hash = splitted[4];
HashBytes = ConvertFromByteString(Hash);
}
else
{
Salt = string.Empty;
- Hash = SplitStorageString[3];
+ Hash = splitted[3];
HashBytes = ConvertFromByteString(Hash);
}
}
else
{
- if (SplitStorageString.Length == 4)
+ if (splitted.Length == 4)
{
- Salt = SplitStorageString[2];
+ Salt = splitted[2];
SaltBytes = ConvertFromByteString(Salt);
- Hash = SplitStorageString[3];
+ Hash = splitted[3];
HashBytes = ConvertFromByteString(Hash);
}
else
{
Salt = string.Empty;
- Hash = SplitStorageString[2];
+ Hash = splitted[2];
HashBytes = ConvertFromByteString(Hash);
}
@@ -83,6 +87,7 @@ namespace MediaBrowser.Model.Cryptography } return Bytes.ToArray(); } + public static string ConvertToByteString(byte[] bytes) { return BitConverter.ToString(bytes).Replace("-", ""); @@ -104,19 +109,18 @@ namespace MediaBrowser.Model.Cryptography public override string ToString()
{ - string OutString = "$"; - OutString += Id; + string outString = "$" +Id; string paramstring = SerializeParameters(); if (!string.IsNullOrEmpty(paramstring)) { - OutString += $"${paramstring}"; + outString += $"${paramstring}"; } if (!string.IsNullOrEmpty(Salt)) { - OutString += $"${Salt}"; + outString += $"${Salt}"; } - OutString += $"${Hash}";
- return OutString;
+ outString += $"${Hash}";
+ return outString;
}
}
|
