public async Task <Unit> Handle(CreateEntryCommand request, CancellationToken cancellationToken)
        {
            if (!VaultService.ValidateVaultPassword(request.VaultId, request.MasterPassword))
            {
                throw new Exception("Podano nie poprawne hasło");
            }

            var vault = await(from v in PmContext.Vaults
                              where v.Id == request.VaultId
                              select new { v.Id }
                              ).FirstOrDefaultAsync();

            if (vault == null)
            {
                throw new Exception();
            }

            Entry entry = new Entry();

            if (String.IsNullOrEmpty(request.Login) || String.IsNullOrEmpty(request.Password) || String.IsNullOrEmpty(request.Portal))
            {
                throw new Exception("Wrong data");
            }
            entry.Login    = request.Login;
            entry.Password = request.Password;
            entry.Portal   = request.Portal;
            entry.Email    = request.Email;
            entry.VaultId  = vault.Id;

            PmContext.Add(entry);
            await PmContext.SaveChangesAsync();

            return(Unit.Value);
        }
Beispiel #2
0
        public async Task <Unit> Handle(CreateVaultCommand request, CancellationToken cancellationToken)
        {
            var vault = new Vault()
            {
                MasterSalt     = Encryptor.GenerateSalt(),
                MasterPassword = "",
                Name           = request.Name,
                Username       = UserResolverService.GetUsername()
            };

            vault.MasterPassword = CryptoService.HashString(request.MasterPassword, vault.MasterSalt);
            PmContext.Add(vault);
            await PmContext.SaveChangesAsync();

            return(Unit.Value);
        }