public void PasswordRegexTest_TestRegex_ReturnsFalse() { var password = "******"; var passwordRegex = new PasswordRegex(); var result = passwordRegex.IsValid(password); Assert.AreEqual(false, result); }
/// <summary> /// Validates that a password meets minimum requirements. /// </summary> /// <param name="password"></param> /// <param name="results"></param> /// <returns></returns> public virtual bool ValidatePassword(string password, ExecutionResults results) { if (!PasswordRegex.IsMatch(password)) { results.AppendError(PasswordErrorMessage); return(false); } return(true); }
public override async Task <string> Part1Async(string input) { var intMachine = new SynchronousIntMachine(input); var(rooms, collectedItems) = await DiscoverRoomsAndGatherItemsAsync(intMachine); var hullBreachRoom = rooms[HullBreach]; var securityCheckpointRoom = rooms[SecurityCheckpoint]; var pathToSecurityCheck = GetPath(hullBreachRoom, securityCheckpointRoom); await FollowPath(intMachine, pathToSecurityCheck); var nextDirection = securityCheckpointRoom.Doors.Keys.Single(d => d != InverseDirections[pathToSecurityCheck.Last()]); var inventories = collectedItems .Subsets() .Select(x => x.OrderBy(y => y).ToList()) .Append(new List <string>()) .OrderBy(x => Math.Abs(collectedItems.Count / 2 - x.Count)) .ToList(); var currentInventory = inventories.First(); string password = null; foreach (var(newInventory, inventoryIndex) in inventories.WithIndex()) { Progress.Percentage = inventoryIndex * 100.0 / inventories.Count * 4; if (!currentInventory.SequenceEqual(newInventory)) { var stuffToDrop = currentInventory.Except(newInventory).ToList(); var stuffToTake = newInventory.Except(currentInventory).ToList(); foreach (var stuff in stuffToDrop) { _ = await RunMachineAsync(intMachine, string.Concat("drop ", stuff)); } foreach (var stuff in stuffToTake) { _ = await RunMachineAsync(intMachine, string.Concat("take ", stuff)); } } currentInventory = newInventory; var response = await RunMachineAsync(intMachine, nextDirection); var roomNames = RoomNameRegex.Matches(response).OfType <Match>().Select(x => x.Groups[1].Value).ToList(); if (roomNames.Count == 1) { password = PasswordRegex.Match(response).Value; break; } } return(password); }
public bool IsValid(string password) { var passwordRegex = new PasswordRegex(); return(passwordRegex.IsValid(password)); }