예제 #1
0
        public async Task <User> Register(User user, string password)
        {
            byte[] passwordHash, passwordSalt;
            PasswordChecker.CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            var roles = await _roleRepository.GetAll();

            var role = roles.Where(i => i.Name == "REGISTERED_USER").FirstOrDefault();
            var id   = await _userRepository.Add(user);

            var endUser = await _userRepository.GetById(id.ToString());

            await _userRoleRepository.Add(new UserRole()
            {
                UserId = id,
                RoleId = role.Id
            });

            return(endUser);
        }
        public void SetupTests()
        {
            var inputs = new string[] { "1-3 a: abcde", "1-3 b: cdefg", "2-9 c: ccccccccc", "1-4 z: zazaza" };

            pc = new PasswordChecker(inputs);
        }
예제 #3
0
 public void TestPart1()
 {
     Assert.IsTrue(PasswordChecker.IsValid(111111));
     Assert.IsFalse(PasswordChecker.IsValid(223450));
     Assert.IsFalse(PasswordChecker.IsValid(123789));
 }
예제 #4
0
 public void Part2Problem()
 {
     //How many different passwords within the range given in your puzzle input meet these criteria?
     //Your puzzle input is 278384-824795.
     Assert.AreEqual(603, PasswordChecker.PasswordCheck(278384, 824795, true));
 }
예제 #5
0
 public void TestPart2()
 {
     Assert.IsTrue(PasswordChecker.IsValid(112233, true));
     Assert.IsFalse(PasswordChecker.IsValid(123444, true));
     Assert.IsTrue(PasswordChecker.IsValid(111122, true));
 }
예제 #6
0
 public void PasswordChecker_Initialize()
 {
     this.userRepository = new Mock <IUserRepository>();
     this.checker        = new PasswordChecker(userRepository.Object);
 }
예제 #7
0
 public void CheckPassword_TooLong_ReturnsFalse()
 {
     Assert.IsFalse(PasswordChecker.CheckPassword("asdfasdfasdfasdfasdfasdf"));
 }
예제 #8
0
 public void CheckPassword_NoUpperCase_ReturnsFalse()
 {
     Assert.IsFalse(PasswordChecker.CheckPassword("asdfasdf"));
 }
예제 #9
0
 public void CheckPassword_NoSpecialCharacters_ReturnsFalse()
 {
     Assert.IsFalse(PasswordChecker.CheckPassword("aASaASDF"));
 }
예제 #10
0
 public void CheckPassword_GoodPassword_ReturnsTrue()
 {
     Assert.IsTrue(PasswordChecker.CheckPassword("aBcdef12&"));
 }
예제 #11
0
 public void CheckPassword_SameConsecutive_ReturnsFalse()
 {
     Assert.IsFalse(PasswordChecker.CheckPassword("AASaASDF"));
 }
예제 #12
0
 public void CheckPassword_NoLowerCase_ReturnsFalse()
 {
     Assert.IsFalse(PasswordChecker.CheckPassword("ASDFASDF"));
 }
예제 #13
0
 public void CheckPassword_ContainsWhiteSpace_ReturnsFalse()
 {
     Assert.IsFalse(PasswordChecker.CheckPassword("as aasdf"));
 }
예제 #14
0
 public VenusFuelDepot(IOutputWriter outputWriter)
 {
     this.outputWriter = outputWriter;
     passwordChecker   = new PasswordChecker();
 }
예제 #15
0
 public void Setup()
 {
     cut = new PasswordChecker();
 }
예제 #16
0
		public void initializationTest()
		{
			PasswordChecker pc = new PasswordChecker("abla");
			Assert.IsNotNull(pc);
			Assert.AreEqual(pc.Login, "abla");
		}
        public static async Task Start()
        {
            string checkAgainResponse = "";

            string filepath = null;

            using var cancellationTokenSource = new CancellationTokenSource();

            ConsoleCancelEventHandler cancelHandler = (sender, args) => cancellationTokenSource.Cancel();

            Console.CancelKeyPress += cancelHandler;

            do
            {
                Console.WriteLine("your password:"******"the hash is: {hash}");

                if (filepath == null)
                {
                    Console.WriteLine("file path to hash file:");
                    filepath = Console.ReadLine();
                }

                if (File.Exists(filepath))
                {
                    filepath = Path.GetFullPath(filepath);

                    Console.WriteLine(filepath);

                    Console.WriteLine("search started");
                    var time = new Stopwatch();
                    time.Start();

                    await AnsiConsole.Progress()
                    .StartAsync(async ctx =>
                    {
                        // Define tasks
                        var progressTask = ctx.AddTask("[green]Searching for password hash[/]");;

                        var progressHandler = new Progress <double>(value => progressTask.Value = progressTask.Value);

                        int occurrences = 0;

                        try
                        {
                            occurrences = await PasswordChecker.FindPassword(hash, filepath, progressHandler, cancellationTokenSource.Token);
                        }
                        catch (OperationCanceledException ex)
                        {
                            Console.WriteLine("Canceled.");
                            return;
                        }

                        time.Stop();
                        Console.WriteLine($"Search took {time.Elapsed}");

                        if (occurrences > 0)
                        {
                            Console.WriteLine($"Bad news: Your password was found inside the database. This password has been seen {occurrences} times before");
                        }
                        else
                        {
                            Console.WriteLine("Good news: No occurences found");
                        }
                    });

                    do
                    {
                        Console.WriteLine("Check another password? (Y/N)");
                        checkAgainResponse = Console.ReadLine();
                    }while (!checkAgainResponse.Equals("Y", StringComparison.CurrentCultureIgnoreCase) &&
                            !checkAgainResponse.Equals("N", StringComparison.CurrentCultureIgnoreCase));
                }
                else
                {
                    Console.WriteLine("filepath invaild or not found");
                }
            } while (checkAgainResponse.Equals("Y", StringComparison.CurrentCultureIgnoreCase));

            Console.CancelKeyPress -= cancelHandler;
        }