public void CreateResponseComplexType() { var passwordCriteria = new PasswordCriteria(); var result = ControllerHelper.CreateResponse(passwordCriteria); Assert.IsInstanceOfType(result.Value, typeof(PasswordCriteria)); Assert.AreSame(passwordCriteria, result.Value); }
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]}"); } } }
/// <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); }
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); }
public void PasswordCriteriaIsValid(bool expected, string password) { var result = PasswordCriteria.IsValid(password); Assert.AreEqual(expected, result); }
public bool PostValidatePassword([FromBody] PasswordChangeRequest data) { return(PasswordCriteria.IsValid(data.Password)); }