コード例 #1
0
        public void CreateResponseComplexType()
        {
            var passwordCriteria = new PasswordCriteria();
            var result           = ControllerHelper.CreateResponse(passwordCriteria);

            Assert.IsInstanceOfType(result.Value, typeof(PasswordCriteria));
            Assert.AreSame(passwordCriteria, result.Value);
        }
コード例 #2
0
ファイル: Day2.cs プロジェクト: sweenist/AoC2020
        public static void TestProblem2()
        {
            var testCases = new Dictionary <string, bool> {
                { "1-3 a: abcde", true },
                { "1-3 b: cdefg", false },
                { "2-9 c: ccccccccc", false },
            };

            foreach (var key in testCases.Keys)
            {
                var target = new PasswordCriteria(_regex.Match(key).Groups);
                if (target.MeetsPart2Criteria != testCases[key])
                {
                    Console.WriteLine($"ERROR: {key} criteria should be {testCases[key]}");
                }
            }
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task <bool> UpdatePassword(int userId, string password)
        {
            if (!PasswordCriteria.IsValid(password))
            {
                return(false);
            }

            var user = await Context.Users.FindAsync(userId);

            if (user == null)
            {
                return(false);
            }

            user.PasswordHash = AuthenticationHelper.EncryptPassword(password);

            Context.Users.Update(user);

            await Context.SaveChangesAsync();

            return(true);
        }
コード例 #4
0
        internal async Task <int> InsertUserInternalAsync(Models.TransferObjects.User user, bool isVerified)
        {
            if (!PasswordCriteria.IsValid(user.Password))
            {
                return(0);
            }

            var passwordHash = AuthenticationHelper.EncryptPassword(user.Password);

            var u = await Context.Users.AddAsync(new Models.DbModels.User
            {
                FirstName    = user.FirstName,
                LastName     = user.LastName,
                Email        = user.Email,
                PictureUrl   = user.PictureUrl,
                PasswordHash = passwordHash,
                IsVerified   = isVerified
            });

            await Context.SaveChangesAsync();

            return(u.Entity.Id);
        }
コード例 #5
0
        public void PasswordCriteriaIsValid(bool expected, string password)
        {
            var result = PasswordCriteria.IsValid(password);

            Assert.AreEqual(expected, result);
        }
コード例 #6
0
 public bool PostValidatePassword([FromBody] PasswordChangeRequest data)
 {
     return(PasswordCriteria.IsValid(data.Password));
 }