Example #1
0
 public async Task <User> GetById(int userId)
 {
     return(await Task.Run(() =>
     {
         GetByIdCount++;
         if (db.Any(f => f.UserId == userId))
         {
             return db.Where(f => f.UserId == userId).First();
         }
         else if (userId == 1)
         {
             return new User
             {
                 AppKey = "CHAVE",
                 Key = "USUARIO",
                 CheckKey = "CHAVE_DE_SEGURANÇA",
                 Password = PasswordCreator.Create("SENHA", "CHAVE_DE_SEGURANÇA"),
                 UserId = 1
             };
         }
         else
         {
             return User.Invalid <User>();
         }
     }));
 }
Example #2
0
 public async Task <User> GetByKeyToApp(string key, string appKey)
 {
     return(await Task.Run(() =>
     {
         GetByKeyToAppCount++;
         if (db.Any(f => f.Key == key && f.AppKey == appKey))
         {
             return db.Where(f => f.Key == key && f.AppKey == appKey).First();
         }
         else if (key == "USUARIO" && appKey == "CHAVE")
         {
             return new User
             {
                 AppKey = "CHAVE",
                 Key = "USUARIO",
                 CheckKey = "CHAVE_DE_SEGURANÇA",
                 Password = PasswordCreator.Create("SENHA", "CHAVE_DE_SEGURANÇA"),
                 UserId = 1
             };
         }
         else
         {
             return User.Invalid <User>();
         }
     }));
 }
Example #3
0
        private async Task Do()
        {
            var user = await _userRepository.GetById(_userId);

            InvalidUserExceptionCreator.ThrowIfFalse(user.IsValid() && user.AppKey.Equals(_appKey));
            var newPassword = PasswordCreator.Create(_newPassword, user.CheckKey);
            await _userRepository.ChangePassword(_userId, newPassword);
        }
Example #4
0
        private async Task <bool> Do()
        {
            var user = await _userRepository.GetByKeyToApp(_userName, _appKey);

            if (!user.IsValid())
            {
                return(false);
            }
            var newPassword = PasswordCreator.Create(_password, user.CheckKey);

            return(await _userRepository.ChangePasswordByCode(_userName, _code, newPassword, _appKey));
        }
        public void Create_ReturnsCorrectPassword()
        {
            var expected       = "Donald Duck rode his bike in the street";
            var randomizerMock = new Mock <RandomizerBase>();

            randomizerMock.Setup(x => x.GetInt(It.IsAny <int>(), It.IsAny <int>())).Returns(1);
            var passwordCreator = new PasswordCreator(randomizerMock.Object);
            var actual          = passwordCreator.Create();

            Output.WriteLine($"Password: {actual}");
            Assert.Equal(actual, expected);
        }
Example #6
0
        private async Task <string> Do()
        {
            var user = await _userRepository.GetByKeyToApp(_userName, _appKey);

            InvalidUsernameOrPasswordExceptionCreator.ThrowIfFalse(user.IsValid());
            string typedPassword = PasswordCreator.Create(_password, user.CheckKey);

            InvalidUsernameOrPasswordExceptionCreator.ThrowIfFalse(user.Password.Equals(typedPassword));
            user.Password = String.Empty;
            user.CheckKey = String.Empty;
            string token = _tokenCreator.Create(user, _device, _appKey);
            await _tokenRepository.Create(user.UserId, _device, token);

            return(token);
        }
Example #7
0
 private string CreatePasswordHash(string passord, string key) => PasswordCreator.Create(passord, key);