public void SameInputEncryptedTwiceComparison()
        {
            var service = new CryptographyService();
            var input = "test";

            var encryptOne = service.Encrypt(input);
            var encryptTwo = service.Encrypt(input);

            Assert.AreEqual(encryptOne, encryptTwo);
        }
        public Advertiser AddNewAdvertiser(SaveAdvertiserMessage message)
        {
            var newAdvertiser = new Advertiser();

            newAdvertiser.Name     = message.Name;
            newAdvertiser.Password = _cryptographyService.Encrypt(message.Password);
            newAdvertiser.Email    = message.Email;

            _advertiserRepository.Add(newAdvertiser);
            _advertiserRepository.SaveChanges();

            return(newAdvertiser);
        }
        public IPrincipal AuthenticateAdministrator(AuthenticateMessage message)
        {
            var administrator = _administratorRepository.Get(message.Username);

            if (administrator == null)
            {
                throw new InvalidUsernameException();
            }

            var encryptedProvidedPassword = _cryptographyService.Encrypt(message.Password);

            if (!administrator.Password.Equals(encryptedProvidedPassword))
            {
                throw new InvalidPasswordException();
            }

            return(Authenticate(AUTHENTICATION_TYPE_ADMIN));
        }
Exemplo n.º 4
0
        public void Create(string username, string password)
        {
            var account = new Administrator();

            account.Name     = username;
            account.UserName = username;
            account.Password = _cryptographyService.Encrypt(password);
            _administratorRepository.Add(account);
            _administratorRepository.SaveChanges();
        }