Untitled
unknown
plain_text
2 years ago
3.4 kB
10
Indexable
JObject defaultType = null;
//string hasPasswordVal = "{SSHA}A1JRXsUNYhD7HW1JfE1OEQLblWRicLIcxw3uNA==";
//string REGEX_ALGORITHM = "(?<={).*(?=})";
//string REGEX_PASSWORD = "(?<=}).*";
//if (!new Regex(REGEX_ALGORITHM).IsMatch(hasPasswordVal))
//{
// throw new Exception("Unable to parse algorithm from password string.");
//}
//var algoirthm = new Regex(REGEX_ALGORITHM).Matches(hasPasswordVal).FirstOrDefault().Value;
//if (!new Regex(REGEX_PASSWORD).IsMatch(hasPasswordVal))
//{
// throw new Exception("Unable to parse algorithm from password string.");
//}
//var passwordAndSalt = new Regex(REGEX_PASSWORD).Matches(hasPasswordVal).FirstOrDefault().Value;
//var passwordBuffer = Convert.ToBase64String(Encoding.UTF8.GetBytes(passwordAndSalt));
// //check user.algorithm for hash type or hook type
if (!string.IsNullOrEmpty(user.algorithm))
{
JObject hash = null;
switch (user.algorithm)
{
case "SSHA":
hash = new JObject(
new JProperty("algorithm", "SHA-1"),
new JProperty("salt", user.salt),
new JProperty("value", user.value),
new JProperty("saltOrder", _saltOrder)
);
break;
case "SSHA256":
hash = new JObject(
new JProperty("algorithm", "SHA-256"),
new JProperty("salt", user.salt),
new JProperty("value", user.value),
new JProperty("saltOrder", _saltOrder)
);
break;
default:
break;
}
password = new JObject(
new JProperty("hash", hash)
);
credentials = new JObject(
new JProperty("password", password)
);
}
else
{
defaultType = new JObject(
new JProperty("type", "default")
);
password = new JObject(
new JProperty("hook", defaultType)
);
credentials = new JObject(
new JProperty("password", password)
);
}
jsonObject = new JObject(
new JProperty("profile", profile),
new JProperty("credentials", credentials)
);
//var json = JsonConvert.SerializeObject(jsonObject);
//var json = JsonConvert.SerializeObject(jsonObject,
// new JsonSerializerSettings
// {
// NullValueHandling = NullValueHandling.Ignore,
// });
var json = JsonConvert.SerializeObject(jsonObject, Formatting.Indented, new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
});Editor is loading...