mirror of
https://github.com/bitwarden/server.git
synced 2025-02-13 01:21:29 +01:00
move to private method
This commit is contained in:
parent
3ceda47bf9
commit
8bc523ee84
@ -274,24 +274,7 @@ public class AccountsController : Controller
|
||||
var kdfInformation = await _userRepository.GetKdfInformationByEmailAsync(model.Email);
|
||||
if (kdfInformation == null)
|
||||
{
|
||||
if (_defaultKdfHmacKey == null)
|
||||
{
|
||||
kdfInformation = _defaultKdfResults[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Compute the HMAC hash of the email
|
||||
var hmacMessage = Encoding.UTF8.GetBytes(model.Email.Trim().ToLowerInvariant());
|
||||
using var hmac = new System.Security.Cryptography.HMACSHA256(_defaultKdfHmacKey);
|
||||
var hmacHash = hmac.ComputeHash(hmacMessage);
|
||||
// Convert the hash to a number
|
||||
var hashHex = BitConverter.ToString(hmacHash).Replace("-", string.Empty).ToLowerInvariant();
|
||||
var hashFirst8Bytes = hashHex.Substring(0, 16);
|
||||
var hashNumber = long.Parse(hashFirst8Bytes, System.Globalization.NumberStyles.HexNumber);
|
||||
// Find the default KDF value for this hash number
|
||||
var hashIndex = (int)(Math.Abs(hashNumber) % _defaultKdfResults.Count);
|
||||
kdfInformation = _defaultKdfResults[hashIndex];
|
||||
}
|
||||
kdfInformation = GetDefaultKdf(model.Email);
|
||||
}
|
||||
return new PreloginResponseModel(kdfInformation);
|
||||
}
|
||||
@ -310,4 +293,26 @@ public class AccountsController : Controller
|
||||
Token = token
|
||||
};
|
||||
}
|
||||
|
||||
private UserKdfInformation GetDefaultKdf(string email)
|
||||
{
|
||||
if (_defaultKdfHmacKey == null)
|
||||
{
|
||||
return _defaultKdfResults[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Compute the HMAC hash of the email
|
||||
var hmacMessage = Encoding.UTF8.GetBytes(email.Trim().ToLowerInvariant());
|
||||
using var hmac = new System.Security.Cryptography.HMACSHA256(_defaultKdfHmacKey);
|
||||
var hmacHash = hmac.ComputeHash(hmacMessage);
|
||||
// Convert the hash to a number
|
||||
var hashHex = BitConverter.ToString(hmacHash).Replace("-", string.Empty).ToLowerInvariant();
|
||||
var hashFirst8Bytes = hashHex.Substring(0, 16);
|
||||
var hashNumber = long.Parse(hashFirst8Bytes, System.Globalization.NumberStyles.HexNumber);
|
||||
// Find the default KDF value for this hash number
|
||||
var hashIndex = (int)(Math.Abs(hashNumber) % _defaultKdfResults.Count);
|
||||
return _defaultKdfResults[hashIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user