public IActionResult CreatePassword([FromBody] PasswordEntryCreateDto passwordEntryCreateDto)
        {
            bool BOOL_IsJWtTokenRepudied;

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            // Extract the Credential element that has the same username received
            Credential selectedCredential = _vaultDbContext.Credentials.Where(credential => credential.Username.Equals(((ClaimsIdentity)HttpContext.User.Identity).FindFirst("username").Value)).FirstOrDefault();

            // Checks if the JWT token is repudied
            _memoryCache.TryGetValue(Request.Headers[HeaderNames.Authorization], out BOOL_IsJWtTokenRepudied);
            if (null == selectedCredential || BOOL_IsJWtTokenRepudied)
            {
                return(Unauthorized());
            }

            /* Sets the encrypted password using the InitId request header parameter as key*/
            PasswordEntry passwordEntry = _mapper.Map <PasswordEntry>(passwordEntryCreateDto);

            /* Assign the password entry foreign key with the logged credential primary key */
            passwordEntry.CredentialFK = selectedCredential.Id;

            // Adds the entry password to EF and writes to the database
            _vaultDbContext.Passwords.Add(passwordEntry);
            _vaultDbContext.SaveChanges();

            // After, redirect the browser to the ReadPasswordById Action(see the below function)
            return(CreatedAtAction(nameof(ReadPasswordById), new { ID = passwordEntry.Id }, passwordEntry));
        }
 public void Create(PasswordEntry entry)
 {
     lock (_syncLock)
     {
         _dictionary.Add(entry.Id, entry);
     }
 }
        public IActionResult DeletePassword(int id)
        {
            bool BOOL_IsJWtTokenRepudied;

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            // Extract the Credential element that has the same username received
            Credential selectedCredential = _vaultDbContext.Credentials.Where(credential => credential.Username.Equals(((ClaimsIdentity)HttpContext.User.Identity).FindFirst("username").Value)).FirstOrDefault();

            // Checks if the JWT token is repudied
            _memoryCache.TryGetValue(Request.Headers[HeaderNames.Authorization], out BOOL_IsJWtTokenRepudied);

            if (null == selectedCredential || BOOL_IsJWtTokenRepudied)
            {
                return(Unauthorized());
            }

            // Extracts the PasswordEntry that has the received ID
            PasswordEntry passwordEntry = _vaultDbContext.Passwords.SingleOrDefault(password => password.Id == id && password.CredentialFK == selectedCredential.Id);

            if (null == passwordEntry)
            {
                return(NotFound());
            }

            _vaultDbContext.Passwords.Remove(passwordEntry);
            _vaultDbContext.SaveChanges();

            return(Ok());
        }
 public void Create(PasswordEntry entry)
 {
     lock (_syncLock)
     {
         _dictionary.Add(entry.Id, entry);
     }
 }
        private async Task <bool> ValidarControles()
        {
            bool   b_error = false;
            string s_msg   = "";

            if (string.IsNullOrEmpty(EmailEntry.Text))
            {
                s_msg   = "Debe Ingresar un usuario";
                b_error = true;
                EmailEntry.Focus();
            }

            if (string.IsNullOrEmpty(PasswordEntry.Text) && !b_error)
            {
                s_msg   = "Debe Ingresar una clave";
                b_error = true;
                PasswordEntry.Focus();
            }

            if (b_error)
            {
                await DisplayAlert("Error", s_msg, "Aceptar");
            }
            return(b_error);
        }
        protected override async Task OnDisappearingAnimationBeginAsync()
        {
            var taskSource = new TaskCompletionSource <bool>();

            var currentHeight = FrameContainer.Height;

            await Task.WhenAll(
                UsernameEntry.FadeTo(0),
                PasswordEntry.FadeTo(0),
                LoginButton.FadeTo(0));

            FrameContainer.Animate("HideAnimation", d =>
            {
                FrameContainer.HeightRequest = d;
            },
                                   start: currentHeight,
                                   end: 170,
                                   finished: async(d, b) =>
            {
                await Task.Delay(300);
                taskSource.TrySetResult(true);
            });

            await taskSource.Task;
        }
        private async void OnPasswordTextChanged(object sender, TextChangedEventArgs args)
        {
            if (!String.IsNullOrEmpty(args.NewTextValue))
            {
                if (!PasswordHint.IsVisible)
                {
                    PasswordHint.IsVisible = true;
                    PasswordHint.Text      = PasswordEntry.Placeholder;

                    _ = PasswordHint.FadeTo(1, 500, Easing.Linear);
                    _ = PasswordEntry.TranslateTo(0, 10, 500, Easing.CubicOut);
                    _ = PasswordHint.TranslateTo(0, -15, 500, Easing.CubicOut);
                }
            }
            else
            {
                await Task.WhenAll(
                    PasswordHint.FadeTo(0, 500, Easing.Linear),
                    PasswordEntry.TranslateTo(0, 0, 500, Easing.CubicOut),
                    PasswordHint.TranslateTo(0, -10, 500, Easing.CubicOut)
                    );

                PasswordHint.IsVisible = false;
            }
        }
Exemple #8
0
        private void PasswordEntry_Completed(object sender, EventArgs e)
        {
            var input = PasswordEntry.Text;

            if (input == null)
            {
                DisplayAlert("Error", "Password is too short (minimum is 6 characters)", "OK");
                PasswordEntry.Focus();
            }
            else
            {
                input = input.ToLower();
                if (input.Length > 20)
                {
                    DisplayAlert("Error", "Password is too long (maximum is 20 characters)", "OK");
                    PasswordEntry.Focus();
                    return;
                }
                if (input.Length < 6)
                {
                    DisplayAlert("Error", "Password is too short (minimum is 6 characters)", "OK");
                    PasswordEntry.Focus();
                    return;
                }
                if (input.Contains(' '))
                {
                    DisplayAlert("Error", "Password Can't Have Whitespaces", "OK");
                    PasswordEntry.Focus();
                    return;
                }
                LogInButton_Clicked(null, null);
            }
        }
Exemple #9
0
        protected override async void OnAppearingAnimationEnd()
        {
            if (!IsAnimationEnabled)
            {
                return;
            }


            var translateLength = 400u;


            await Task.WhenAll(
                UsernameEntry.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength),
                UsernameEntry.FadeTo(1),
                (new Func <Task>(async() =>
            {
                await Task.Delay(200);
                await Task.WhenAll(
                    PasswordEntry.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength),
                    PasswordEntry.FadeTo(1));
            }))());


            await Task.WhenAll(
                CloseImage.FadeTo(1),
                CloseImage.ScaleTo(1, easing: Easing.SpringOut),
                CloseImage.RotateTo(0),
                LoginButton.ScaleTo(1),
                LoginButton.FadeTo(1));
        }
Exemple #10
0
            public static bool IsValidPart2(PasswordEntry entry)
            {
                var letter1 = entry.Password[entry.Min - 1];
                var letter2 = entry.Password[entry.Max - 1];

                return(letter1 == entry.RequiredLetter ^ letter2 == entry.RequiredLetter);
            }
Exemple #11
0
            public void Should_Return2InValidPasswordCount_When_2InValid()
            {
                var pwEntry1 = new PasswordEntry {
                    Password = "******", PwPolicy = new PasswordPolicy {
                        Letter = 'a', Position1 = 1, Position2 = 2
                    }
                };                                                                                                                              // not valid
                var pwEntry2 = new PasswordEntry {
                    Password = "******", PwPolicy = new PasswordPolicy {
                        Letter = 'a', Position1 = 1, Position2 = 2
                    }
                };                                                                                                                              // not valid
                var pwEntry3 = new PasswordEntry {
                    Password = "******", PwPolicy = new PasswordPolicy {
                        Letter = 'b', Position1 = 1, Position2 = 3
                    }
                };
                var pwEntries = new List <PasswordEntry> {
                    pwEntry1, pwEntry2, pwEntry3
                };

                var sut        = new PasswordReportService(pwEntries);
                var validCount = sut.NumberOfValidPasswords();

                Assert.That(validCount == 1);
            }
Exemple #12
0
 public LoginPage()
 {
     InitializeComponent();
     BindingContext = new LoginDBModel();
     UserNameEntry.SetBinding(Entry.TextProperty, "Username");
     PasswordEntry.SetBinding(Entry.TextProperty, "Passdata");
 }
Exemple #13
0
        private async void LoginButton_Clicked(object sender, EventArgs e)
        {
            // UserDialogs.Instance.ShowLoading("Loading", MaskType.Black); //IsLoading = true;

            if (string.IsNullOrEmpty(PasswordEntry.Text))
            {
                //IsLoading = false;
                UserDialogs.Instance.HideLoading();
                //DependencyService.Get<IMessage>().LongAlert("Password is blank!");
                UserDialogs.Instance.ShowError("Password is blank!", 3000);
                return;
            }

            if (PasswordEntry.Text == App.gAdminPsw)
            {
                Navigation.PushAsync(new MainPage(7));
            }
            else
            {
                UserDialogs.Instance.ShowError("Wrong Password!", 3000);
                PasswordEntry.Focus();
            }


            // UserDialogs.Instance.HideLoading();
        }
Exemple #14
0
        private void PasswordEntry_Completed(object sender, EventArgs e)
        {
            var input = PasswordEntry.Text;

            if (input == null)
            {
                DisplayAlert("Error", "Password should contain at least six characters", "OK");
                PasswordEntry.Focus();
            }
            else
            {
                input = input.ToLower();
                if (input.Length > 15)
                {
                    DisplayAlert("Error", "Password can contain at max fifteen characters", "OK");
                    PasswordEntry.Focus();
                    return;
                }
                if (input.Length < 6)
                {
                    DisplayAlert("Error", "Password should contain at least six characters", "OK");
                    PasswordEntry.Focus();
                    return;
                }
                if (input.Contains(' '))
                {
                    DisplayAlert("Error", "Password Can't Have Whitespaces", "OK");
                    PasswordEntry.Focus();
                    return;
                }
                LogInButton_Clicked(null, null);
            }
        }
Exemple #15
0
        public LoginPage()
        {
            var vm = new LoginViewModel();

            this.BindingContext           = vm;
            vm.DisplayInvalidLoginPrompt += () => DisplayAlert("Sorry", "The credentials you supplied are incorrect.", "Ok");
            InitializeComponent();

            EmailEntry.Completed += (object sender, EventArgs e) => {
                PasswordEntry.Focus();
            };

            PasswordEntry.Completed += (object sender, EventArgs e) => {
                vm.SubmitCommand.Execute(null);
            };

            LoginButton.Clicked += async(sender, e) => {
                var buttonIndex = await PromptSheet.ShowAlert(this.PageContainer, "Oops", "Sorry, the supplied credentials are incorrect. Do you want to try again?", "Yes", new string[] { "No", "Maybe" });

                Debug.WriteLine($"Button with index {buttonIndex} tapped");

                if (buttonIndex == 1)
                {
                    var inputResult = await PromptSheet.ShowInputPopup(this.PageContainer, "We can help!", "May we can send you an email to reset your password.", new InputOptions()
                    {
                        Placeholder = "Your Email"
                    }, new string[] { "Yes, Sent it!", "No, thanks" });

                    Debug.WriteLine($"Button with index {inputResult.ButtonIndex} tapped");
                    Debug.WriteLine($"Input with content {inputResult.InputText}");
                }
            };
        }
        public static void ParseToEntry(PasswordEntry entry, string decryptedFileContent)
        {
            int last = decryptedFileContent.LastIndexOf('}') + 1;

            if (last != decryptedFileContent.Length)
            {
                decryptedFileContent = decryptedFileContent.Substring(0, last);
                Debug.WriteLine("corrupt data recognized");
            }


            //Debug.WriteLine(decryptedFileContent);
            dynamic o = JsonConvert.DeserializeObject(decryptedFileContent);



            foreach (dynamic d in o.usernames)
            {
                Username u = new Username
                {
                    Name     = d.username,
                    Password = d.password,
                    Email    = d.email,
                    Notes    = d.notes,
                    TFA      = d.TFA
                };

                entry.Add(u);
            }
        }
Exemple #17
0
        private PasswordViewModel CreatePasswordViewModel(PasswordEntry password)
        {
            var vm = new PasswordViewModel(password);

            vm.RemoveRequested += OnRemoveRequested;
            return(vm);
        }
        private void updateButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (passwordEntry == null)
                {
                    return;
                }

                string decrypted = EncryptionTool.Decrypt(passwordEntry.Password);
                string password  = passwordEntry.Password;
                if (passwordTextBox.Text != password && passwordTextBox.Text != decrypted)
                {
                    password = passwordTextBox.Text;
                    password = EncryptionTool.Encrypt(password);
                }


                PasswordEntry pe = new PasswordEntry(
                    titleTextBox.Text, password, urlTextBox.Text, commentTextBox.Text);
                user.UpdatePassword(passwordEntry.Title, pe);

                MessageBox.Show("Pavyko atnaujinti slaptažodį");
                ClearFields();
                DisableFields();
                passwordEntry = null;
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }
        public void AddPassword(string name, string password, string masterPassword)
        {
            // Ensure arguments are not blank and password entry does not already exist
            if (!(name?.Length > 0))
            {
                throw new InvalidArgumentException($"Error adding password: Argument '{nameof(name)}' is blank.");
            }
            else if (!(password?.Length > 0))
            {
                throw new InvalidArgumentException($"Error adding password: Argument '{nameof(password)}' is blank.");
            }
            else if (!(masterPassword?.Length > 0))
            {
                throw new InvalidArgumentException($"Error adding password: Argument '{nameof(masterPassword)}' is blank.");
            }
            else if (_passwordContainer.PasswordEntries.Any(e => e.Name == name))
            {
                throw new InvalidEntryException($"Error adding password: Entry '{name}' already exists.");
            }

            // Create new password entry
            PasswordEntry entry = new PasswordEntry();

            // Set name, encrypt and set password
            entry.Name     = name;
            entry.Password = Crypto.Encrypt(password, masterPassword, name);

            // Add new entry to container
            _passwordContainer.PasswordEntries.Add(entry);

            // Save vault
            Save();
        }
Exemple #20
0
        private void EditPass_Clicked(object?sender, EventArgs e)
        {
            var passwd = GtkHelper.GetSelectedValue <PasswordEntry?>(this.LvPasswords, 2);

            if (passwd.HasValue)
            {
                using var dlg = PasswordDialog.CreateFromGladeFile(this, this.group);
                dlg.SetPassword(passwd.Value);
                dlg.Run();
                dlg.Destroy();
                if (dlg.Result)
                {
                    var password = new PasswordEntry
                    {
                        Host     = dlg.Host,
                        User     = dlg.UserName,
                        Password = dlg.Password
                    };
                    if (LvPasswords.Selection.GetSelected(out var iter))
                    {
                        passwordStore.SetValues(iter, password.Host, password.User, password);
                    }
                }
            }
        }
        protected async override Task OnAppearingAnimationEnd()
        {
            var translateLength = 400u;

            await Task.WhenAll(
                Nombre.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength),
                Apellido.FadeTo(1));

            await Task.WhenAll(
                UsernameEntry.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength),
                UsernameEntry.FadeTo(1),
                Profesion.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength),
                Profesion.FadeTo(1),

                (new Func <Task>(async() =>
            {
                await Task.Delay(200);
                await Task.WhenAll(
                    PasswordEntry.TranslateTo(0, 0, easing: Easing.SpringOut, length: translateLength),
                    PasswordEntry.FadeTo(1));
            }))());


            await Task.WhenAll(
                LoginButton.ScaleTo(1),
                LoginButton.FadeTo(1));
        }
Exemple #22
0
        static bool IsPasswordValid(PasswordEntry entry)
        {
            var firstChar  = entry.Password[entry.Position1 - 1];
            var secondChar = entry.Password[entry.Position2 - 1];

            return(firstChar != secondChar && (firstChar == entry.Character || secondChar == entry.Character));
        }
Exemple #23
0
        public VerboseView(PasswordEntry entry)
        {
            _ViewModel  = new VerboseViewModel(this, entry);
            DataContext = _ViewModel;

            InitializeComponent();
        }
Exemple #24
0
 public PasswordViewModel(PasswordEntry password)
 {
     Id             = password.Id;
     UserName       = password.UserName;
     Description    = password.Description;
     _isLazy        = false;
     _passwordEntry = password;
 }
        public LoginPage()
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this, false);

            EmailEntry.Completed    += (sender, e) => PasswordEntry.Focus();
            PasswordEntry.Completed += (sender, e) => (BindingContext as LoginViewModel).ConnectionCommand.Execute(null);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            PasswordEntry passwordEntry = db.PasswordEntries.Find(id);

            db.PasswordEntries.Remove(passwordEntry);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #27
0
 public LoginPage()
 {
     InitializeComponent();
     UserEntry.Completed += (object sender, EventArgs e) =>
     {
         PasswordEntry.Focus();
     };
 }
        public LoginPage()
        {
            InitializeComponent();
            BindingContext = ViewModel;

            UsernameEntry.Completed += (sender, args) => { PasswordEntry.Focus(); };
            PasswordEntry.Completed += (sender, args) => { ViewModel.AuthenticateCommand.Execute(null); };
        }
Exemple #29
0
        public LoginView()
        {
            NavigationPage.SetHasNavigationBar(this, false);

            InitializeComponent();

            UsernameEntry.Completed += (sender, e) => PasswordEntry.Focus();
        }
Exemple #30
0
            public static bool IsValidPart1(PasswordEntry entry)
            {
                var count = entry.Password
                            .Where((l) => l == entry.RequiredLetter)
                            .Count();

                return(entry.Min <= count && count <= entry.Max);
            }
Exemple #31
0
        /// <summary>
        /// Commit password entry creation
        /// </summary>
        private void CreateEntry()
        {
            var copy = PasswordEntry.Copy();

            databaseRepository.AddPasswordEntry(copy);
            iconsService.DownloadIcon(copy.Website);
            Messenger.Default.Send(new EntryAddedMessage(this, copy));
        }
Exemple #32
0
        private void BuildProcess()
        {
            if (process == null)
            {
                process = new Process();
            }

            StringBuilder builder = new StringBuilder(server.ServerAddress);
            builder.AppendFormat("?name={0}", null);

            if (server.Settings.IsPassworded)
            {
                WindowInteropHelper helper = new WindowInteropHelper(Application.Current.MainWindow);
                using (PasswordEntry dialog = new PasswordEntry())
                {
                    SetWindowLong(new HandleRef(dialog, dialog.Handle), -8, helper.Handle.ToInt32());

                    var result = dialog.ShowDialog();

                    if (result == DialogResult.OK)
                    {
                        builder.AppendFormat("?Password={0}", dialog.Password.Text);
                    }
                    else
                    {
                        // TODO: error message... tired.
                        MessageBox.Show("Warning! A passworded server will require a password to enter.",
                            "No password specified",
                            MessageBoxButton.OK,
                            MessageBoxImage.Exclamation);
                    }
                }
            }

            process.StartInfo.Arguments = builder.ToString();
            process.StartInfo.FileName = BuildInstallationPath();
        }
Exemple #33
0
        private string ReadSettings(IntPtr hParentWnd, string serviceUri, ref string userId)
        {
            Log.Verbose("Acquiring username and password");
            INameValueStore storage = new RegistryStorage();
            try
            {
                Log.Verbose("Trying to read username and password from the cache");
                string password;
                storage.Read(serviceUri, "UserName", out userId);
                if (storage.Read(serviceUri, "Password", out password))
                {
                    string pass = Encryption.CurrentUser.Decrypt(password);
                    Log.Verbose("Successfully read Username and password from the cache");
                    return pass;
                }
            }
            catch
            {
            }

            Log.Verbose("Failed reading username and password from the cache. Prompting user");
            var pwdDlg = new PasswordEntry(userId, serviceUri);
            if (pwdDlg.ShowDialog(Win32Window.FromHandle(hParentWnd)) == DialogResult.OK)
            {
                userId = pwdDlg.UserName.Text;
                SaveSettings(userId, serviceUri, pwdDlg.Password.Text);
                return pwdDlg.Password.Text;
            }

            return null;
        }
 public void Update(Guid id, PasswordEntry newData)
 {
     lock (_syncLock)
     {
         PasswordEntry entry;
         if (_dictionary.TryGetValue(id, out entry))
         {
             entry.Title = newData.Title;
             entry.UserName = newData.UserName;
             entry.Password = newData.Password;
         }
     }
 }