// Return password model to be consumed public static PasswordPnwed passwordCheck(PasswordPnwed model) { // variables string password = model.Password.ToString(); string fullHexString = SHA1Hash(password); string prefixHexString = fullHexString.Substring(0, 5).Trim(); string sufixHexString = fullHexString.Substring(5).Trim(); // Get results from API var returnSuffixes = SendAPIRequest(prefixHexString); // Initiate return item and set defaults PasswordPnwed returnItem = new PasswordPnwed(); returnItem.retHex = "Not Pwned"; returnItem.retCount = "0"; // Loop through results to find matches foreach (KeyValuePair <string, string> entry in returnSuffixes) { if (entry.Key.ToString() == sufixHexString.ToUpper()) { returnItem.retHex = entry.Key.ToString(); returnItem.retCount = entry.Value.ToString(); } } return(returnItem); }
public ActionResult PasswordCheck(PasswordPnwed model) { if (ModelState.IsValid) { PasswordPnwed matchingHex = new PasswordPnwed(); try { matchingHex = Globals.passwordCheck(model); model.retCount = matchingHex.retCount; model.retHex = matchingHex.retHex; return(View("Index", model)); } catch (Exception) { throw; } } else { emptyModel.Password = ""; emptyModel.retHex = ""; emptyModel.retCount = ""; return(View("Index", emptyModel)); } }
public void Index() { //Arrange HomeController controller = new HomeController(); // Setup PasswordPnwed model = new PasswordPnwed(); model.Password = "******"; // Act ViewResult result = controller.PasswordCheck(model) as ViewResult; // Assert Assert.IsNotNull(result); }