Esempio n. 1
0
 public AccountDTO AddAccountToCompany(int currentAccountId, AccountCreateDTO newaccount)
 {
     try {
         var current        = _accountRepository.GetAccount(currentAccountId);
         var currentcompany = current.Company;
         if (currentcompany != null)
         {
             if ((current.Type == eAccountType.Owner || current.Type == eAccountType.Administrator) && IsVatInDatabase(currentcompany.VAT) && !IsEmailInDatabase(newaccount.Email))
             {
                 Account account = Mapper.Map <AccountCreateDTO, Account>(newaccount);
                 Company company = currentcompany;
                 string  salt    = PasswordValidationService.GetInstance().GenerateSalt();
                 account.Password = PasswordValidationService.GetInstance().GenerateCryptedPassword(newaccount.Password, salt);
                 account.Salt     = salt;
                 account.Company  = _companyRepository.AddNewCompany(company);
                 account          = _accountRepository.AddNewAccount(account);
                 var accountviewmodel = Mapper.Map <Account, AccountDTO>(account);
                 return(Mapper.Map <Account, AccountDTO>(current));
             }
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
     return(null);
 }
Esempio n. 2
0
        public AccountDTO Login(string username, string pass)
        {
            AccountDTO accountViewModel = null;

            try
            {
                if (!string.IsNullOrWhiteSpace(username))
                {
                    Account account = _accountRepository.GetAccount(username);
                    if (PasswordValidationService.GetInstance().ValidatePassword(pass, account.Password, account.Salt))
                    {
                        //_log.LogLoginLogout(account.ID, eLoginType.Login);
                        accountViewModel = Mapper.Map <Account, AccountDTO>(account);
                        if (account.Company != null)
                        {
                            var company = Mapper.Map <Company, CompanyDTO>(account.Company);
                            accountViewModel.Company = company;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(accountViewModel);
        }
        public ActionResult RegisterUser(LoginModel loginModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(loginModel));
            }


            var validationService = new PasswordValidationService();

            if (loginModel.Password != loginModel.ConfirmPassword)
            {
                ModelState.AddModelError("Password", "As senhas não conferem");
                return(View(loginModel));
            }

            if (validationService.MeasurePasswordStrength(loginModel.Password) < 100)
            {
                ModelState.AddModelError("Password", "Senha não considerada forte. Por favor, coloque uma nova senha");
                return(View(loginModel));
            }

            loginModel.Password        = _desEncryptor.Encrypt(loginModel.Password);
            loginModel.ConfirmPassword = _desEncryptor.Encrypt(loginModel.ConfirmPassword);

            _repository.Save(loginModel);

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 4
0
        public IHttpActionResult Get(string word)
        {
            var validation = new PasswordValidationService();
            var response   = validation.MeasurePasswordStrength(word);

            return(Ok(response));
        }
        public void Should_IsPropertyValid(string[] match, string property, bool expectedIsValid)
        {
            var validator = new PasswordValidationService();
            var isValid   = validator.IsPropertyValid(match, property);

            Assert.Equal(expectedIsValid, isValid);
        }
Esempio n. 6
0
        public override bool IsValid(object value)
        {
            const double maxPasswordStrength = 100;

            var validationService = new PasswordValidationService();

            return(validationService.MeasurePasswordStrength((string)value) == maxPasswordStrength);
        }
Esempio n. 7
0
        public AccountDTO CreateNewAccount(AccountCreateDTO newaccount)
        {
            try {
                if (newaccount.Email.IsValidEmail() && !IsEmailInDatabase(newaccount.Email))
                {
                    Account account = Mapper.Map <AccountCreateDTO, Account>(newaccount);

                    string salt = PasswordValidationService.GetInstance().GenerateSalt();
                    account.Password = PasswordValidationService.GetInstance().GenerateCryptedPassword(newaccount.Password, salt);
                    account.Salt     = salt;
                    account          = _accountRepository.AddNewAccount(account);
                    var accountviewmodel = Mapper.Map <Account, AccountDTO>(account);
                    return(accountviewmodel);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(null);
        }
Esempio n. 8
0
 public bool UpdatePassword(AccountUpdatePasswordViewModel accountviewmodel)
 {
     try
     {
         var    account = _accountRepository.GetAccount(accountviewmodel.ID);
         string salt    = PasswordValidationService.GetInstance().GenerateSalt();
         string oldpass = PasswordValidationService.GetInstance().GenerateCryptedPassword(accountviewmodel.OldPassword, account.Salt);
         if (oldpass.Equals(account.Password) && accountviewmodel.NewPassword.Equals(accountviewmodel.ConfirmedPassword))
         {
             account.Password = PasswordValidationService.GetInstance().GenerateCryptedPassword(accountviewmodel.NewPassword, salt);
             account.Salt     = salt;
             _accountRepository.UpdateAccount(account);
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Esempio n. 9
0
        public string Generate(int length, ValidationType validationType)
        {
            var passwordValidation = new PasswordValidationService();

            var wordChar = GenerateChars(length, validationType);
            var word     = new String(wordChar);
            var measuredPasswordStrength = passwordValidation.MeasurePasswordStrength(word);

            if (validationType == ValidationType.Strong)
            {
                while (measuredPasswordStrength != 100)
                {
                    wordChar = GenerateChars(length, validationType);
                    word     = new String(wordChar);
                    measuredPasswordStrength = passwordValidation.MeasurePasswordStrength(word);
                }
            }
            else if (validationType == ValidationType.Medium)
            {
                while (measuredPasswordStrength != 50)
                {
                    wordChar = GenerateChars(length, validationType);
                    word     = new String(wordChar);
                    measuredPasswordStrength = passwordValidation.MeasurePasswordStrength(word);
                }
            }
            else if (validationType == ValidationType.Weak)
            {
                while (measuredPasswordStrength != 20)
                {
                    wordChar = GenerateChars(length, validationType);
                    word     = new String(wordChar);
                    measuredPasswordStrength = passwordValidation.MeasurePasswordStrength(word);
                }
            }

            return(word);
        }
Esempio n. 10
0
        public void ShouldBeAValidPassword()
        {
            PasswordValidationService service = new PasswordValidationService();

            Assert.True(service.IsValid("D@tabase1"));
        }
Esempio n. 11
0
        public void ShouldBeAnInvalidPassword(string value)
        {
            PasswordValidationService service = new PasswordValidationService();

            Assert.False(service.IsValid(value));
        }
 public void Init()
 {
     _passwordGenerator         = new PasswordGenerateService();
     _passwordValidationService = new PasswordValidationService();
 }
        public void ShouldNot_IsPropertyValid(string[] match, string nonExistingProperty)
        {
            var validator = new PasswordValidationService();

            Assert.Throws <ArgumentException>("property", () => validator.IsPropertyValid(match, nonExistingProperty));
        }