public void EnsurePositiveCharacterCount_PositiveCount_DoesNotThrow() { // Arrange var characters = new Dictionary <CharacterVariant, string>(); var passwordGeneratorHelper = new PasswordGeneratorHelper(characters); int characterCount = 12; // Act and Assert passwordGeneratorHelper.EnsurePositiveCharacterCount(characterCount); }
public void _12文字のPassword生成() { PasswordType[] types = new[] { PasswordType.Alphabet, PasswordType.Number }; string password = PasswordGeneratorHelper.Create(12, types); Assert.AreEqual(12, password.Length); }
public void EnsurePositiveCharacterVariantCount_NonPositiveCount_ThrowsArgumentException() { // Arrange var characters = new Dictionary <CharacterVariant, string>(); var passwordGeneratorHelper = new PasswordGeneratorHelper(characters); var characterVariants = new CharacterVariant[] { }; // Assert Assert.Throws <ArgumentException>(() => passwordGeneratorHelper.EnsurePositiveCharacterVariantCount(characterVariants)); }
public void AddCharacterVariantsToDictionary_StateUnderTest_ExpectedBehavior() { // Arrange var characters = new Dictionary <CharacterVariant, string>(); var passwordGeneratorHelper = new PasswordGeneratorHelper(characters); var characterVariants = new[] { CharacterVariant.Lowercase, CharacterVariant.Special }; // Act passwordGeneratorHelper.AddCharacterVariantsToDictionary(characterVariants); // Assert characters.Should().HaveCount(characterVariants.Length); }
public void EnsurePositiveCharacterCount_NonPositiveCount_ThrowsArgumentException() { // Arrange var characters = new Dictionary <CharacterVariant, string>(); characters.Add(CharacterVariant.Digits, CharacterLists.Digits); characters.Add(CharacterVariant.Lowercase, CharacterLists.Lowercase); characters.Add(CharacterVariant.Uppercase, CharacterLists.Uppercase); var passwordGeneratorHelper = new PasswordGeneratorHelper(characters); int characterCount = 0; // Act and Assert Assert.Throws <ArgumentException>(() => passwordGeneratorHelper.EnsurePositiveCharacterCount(characterCount)); }
public void EnsurePositiveCharacterVariantCount_PositiveCount_DoesNotThrow() { // Arrange var characters = new Dictionary <CharacterVariant, string>(); characters.Add(CharacterVariant.Digits, CharacterLists.Digits); characters.Add(CharacterVariant.Lowercase, CharacterLists.Lowercase); characters.Add(CharacterVariant.Uppercase, CharacterLists.Uppercase); var passwordGeneratorHelper = new PasswordGeneratorHelper(characters); var characterVariants = new[] { CharacterVariant.Lowercase, CharacterVariant.Special }; // Act and Assert passwordGeneratorHelper.EnsurePositiveCharacterVariantCount(characterVariants); }
public void GetRandom_RunTwice_ValuesShouldBeDifferent() { // Arrange var characters = new Dictionary <CharacterVariant, string>(); var passwordGeneratorHelper = new PasswordGeneratorHelper(characters); int maxValue = 1000; // Act var result1 = passwordGeneratorHelper.GetRandom(maxValue); var result2 = passwordGeneratorHelper.GetRandom(maxValue); // Assert result1.Should().NotBe(result2); }
/// <summary> /// Creates a user entity with randomized password. /// </summary> /// <param name="email">Email to create user with.</param> /// <returns>Created user entity.</returns> private UserEntity CreateUserEntityWithRandomPassword(string email) { var password = PasswordGeneratorHelper.GeneratePassword(useLowercase: true, useUppercase: true, useNumbers: true, useSpecial: true, passwordSize: 50); var passwordHash = PasswordHasherHelper.HashPassword(password); return(new UserEntity() { Email = email, PasswordHash = passwordHash, ApplicationRoles = new List <ApplicationUserRoleEntity>() }); }
public void 数値とalphabetのPassword生成() { PasswordType[] types = new[] { PasswordType.Alphabet, PasswordType.Number }; string password = PasswordGeneratorHelper.Create(10, types); var hasAlphabet = new Regex(@"[A-Za-z]+"); var hasNumber = new Regex(@"[0-9]+"); Assert.IsTrue(hasNumber.IsMatch(password)); Assert.IsTrue(hasAlphabet.IsMatch(password)); }
public void GetRandomCharacterVariant_StateUnderTest_ExpectedBehavior() { // Arrange var characters = new Dictionary <CharacterVariant, string>(); characters.Add(CharacterVariant.Digits, CharacterLists.Digits); characters.Add(CharacterVariant.Lowercase, CharacterLists.Lowercase); characters.Add(CharacterVariant.Uppercase, CharacterLists.Uppercase); var passwordGeneratorHelper = new PasswordGeneratorHelper(characters); // Act var result = passwordGeneratorHelper.GetRandomCharacterVariant(); // Assert characters.Should().ContainKey(result); }
public void GetRandomCharacterVariant() { // Arrange var characters = new Dictionary <CharacterVariant, string> { { CharacterVariant.Digits, CharacterLists.Digits }, { CharacterVariant.Lowercase, CharacterLists.Lowercase }, { CharacterVariant.Uppercase, CharacterLists.Uppercase } }; var passwordGeneratorHelper = new PasswordGeneratorHelper(characters); // Act var result = passwordGeneratorHelper.GetRandomCharacterVariant(); // Assert characters.Should().ContainKey(result); }
public void CreatePasswordString_StateUnderTest_ExpectedBehavior() { // Arrange var characters = new Dictionary <CharacterVariant, string>(); characters.Add(CharacterVariant.Digits, CharacterLists.Digits); characters.Add(CharacterVariant.Lowercase, CharacterLists.Lowercase); characters.Add(CharacterVariant.Uppercase, CharacterLists.Uppercase); var passwordGeneratorHelper = new PasswordGeneratorHelper(characters); int characterCount = 12; // Act var result = passwordGeneratorHelper.CreatePasswordString(characterCount); // Assert _outputHelper.WriteLine(result); }
public void CreatePasswordString() { // Arrange var characters = new Dictionary <CharacterVariant, string> { { CharacterVariant.Digits, CharacterLists.Digits }, { CharacterVariant.Lowercase, CharacterLists.Lowercase }, { CharacterVariant.Uppercase, CharacterLists.Uppercase } }; var passwordGeneratorHelper = new PasswordGeneratorHelper(characters); var characterCount = 12; // Act var result = passwordGeneratorHelper.CreatePasswordString(characterCount); // Assert _outputHelper.WriteLine(result); }
public async Task <Message_Dto> reset_user_access(string UserName) { var user = await _userManager.FindByNameAsync(UserName); if (user == null) { return(null); } if (await _userManager.HasPasswordAsync(user)) { try { var new_Password = PasswordGeneratorHelper.password(); await _userManager.RemovePasswordAsync(user); await _userManager.AddPasswordAsync(user, new_Password); // send mail or sms to share the new password. _email.sendWelcomeEmailSendgrid(user.Email, user.FirstName, new WelcomeEmail { name = user.FirstName + " " + user.LastName, username = user.UserName, password = new_Password, customerServiceEmail = _config.GetSection("Sendgrid:customerServiceEmail").Value, customerServiceNumber = _config.GetSection("Sendgrid:customerServiceNumber").Value } ); // if role is retails send email ==> to be study as a way to limit sms usage _orangesms.send_SMS(user.PhoneNumber, "Votre compte a ete reconfigure avec ce nouveau password :"******"Bien vouloir vous connecter"); return(new Message_Dto { message_en = "User is reset ", message_fr = "Utilisateur est reconfigure" }); } catch (Exception ex) { _logger.LogError("Communication error issue sending reset message notification" + ex.Message); } } return(null); }
public PasswordGenerator() { _characters = new Dictionary <CharacterVariant, string>(); _generatorHelper = new PasswordGeneratorHelper(_characters); }