/// <summary>
        /// Gets All Passwords for the Supplied User.
        /// </summary>
        /// <param name="user">User for whom Passwords are required.</param>
        /// <returns>List of Passwords for the supplied User.</returns>
        private List <Password> GetAllUserPasswords(User user)
        {
            if (ValidationService.Instance().User(user))
            {
                //List<Password> passwords = CryptoService.Instance().Decrypt(user, PasswordsData.Instance().GetUserPasswords(user));
                List <Password> passwords = PasswordsData.Instance().GetUserPasswords(user);

                if (passwords != null)//i am not using the validation service here because passwords are not yet decrypted and may return false when validation called -gul:0401171228
                {
                    passwords = CryptoService.Instance().DecryptUserPasswords(user, passwords);

                    if (ValidationService.Instance().Passwords(passwords))
                    {
                        return(passwords);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Gets All Passwords for the Supplied User.
        /// </summary>
        /// <param name="settings">Settings the Password is to be updated.</param>
        /// <returns>List of Passwords for the supplied User.</returns>
        public Task <List <Password> > GetAllPasswordsAsync(Settings settings)
        {
            return(Task.Factory.StartNew(() =>
            {
                List <Password> passwords = PasswordsData.Instance().GetPasswords();

                if (passwords != null)
                {
                    passwords = CryptoService.Instance().DecryptPasswords(settings.Master, passwords);

                    if (ValidationService.Instance().Passwords(passwords))
                    {
                        return passwords;
                    }
                    else
                    {
                        return null;
                    }
                }
                else
                {
                    return null;
                }
            }));
        }
        /// <summary>
        /// Gets All Passwords for the Supplied User.
        /// </summary>
        /// <param name="user">User for whom Passwords are required.</param>
        /// <returns>List of Passwords for the supplied User.</returns>
        public Task <List <Password> > GetAllUserPasswordsAsync(User user)
        {
            return(Task.Factory.StartNew(() =>
            {
                if (ValidationService.Instance().User(user))
                {
                    //List<Password> passwords = CryptoService.Instance().Decrypt(user, PasswordsData.Instance().GetUserPasswords(user));
                    List <Password> passwords = PasswordsData.Instance().GetUserPasswords(user);

                    if (passwords != null)//i am not using the validation service here because passwords are not yet decrypted and may return false when validation called -gul:0401171228
                    {
                        passwords = CryptoService.Instance().DecryptUserPasswords(user, passwords);

                        if (ValidationService.Instance().Passwords(passwords))
                        {
                            return passwords;
                        }
                        else
                        {
                            return null;
                        }
                    }
                    else
                    {
                        return null;
                    }
                }
                else
                {
                    return null;
                }
            }));
        }
        /// <summary>
        /// Updates the supplied List of Passwords.
        /// </summary>
        /// <param name="user">User for whom the Password is to be updated.</param>
        /// <param name="passwords">List of Passwords to be updated.</param>
        /// <returns>List of Password: The updated passwords.</returns>
        public Task <User> ChangeMasterEncryption(User user, string NewMaster)
        {
            return(Task.Factory.StartNew(() =>
            {
                if (ValidationService.Instance().User(user))
                {
                    List <Password> allPasswords = GetAllUserPasswords(user);

                    user.Master = NewMaster;
                    user = UsersService.Instance().UpdateUser(user);

                    if (PasswordsData.Instance().UpdateUserPasswords(user, CryptoService.Instance().EncryptUserPasswords(user, allPasswords)) > 0)
                    {
                        return user;
                    }
                    else
                    {
                        return null;
                    }
                }
                else
                {
                    return null;
                }
            }));
        }
        /// <summary>
        /// Changes the master for encryption.
        /// </summary>
        /// <param name="settings">Settings the Password is to be updated.</param>
        /// <param name="NewMaster">The new master to be updated.</param>
        /// <returns>List of Password: The updated passwords.</returns>
        public Task <Settings> ChangeMasterEncryption(Settings settings, string NewMaster)
        {
            return(Task.Factory.StartNew(async() =>
            {
                if (ValidationService.Instance().Settings(settings))
                {
                    List <Password> allPasswords = GetAllPasswords(settings);

                    settings.Master = NewMaster;
                    settings = await SettingsService.Instance().UpdateSettingsAsync(settings);

                    // to encrypt passes
                    if (PasswordsData.Instance().UpdatePasswords(CryptoService.Instance().EncryptPasswords(settings.Master, allPasswords)) > 0)
                    {
                        return settings;
                    }
                    else
                    {
                        return null;
                    }
                }
                else
                {
                    return null;
                }
            }).Result);
        }
Esempio n. 6
0
        /// <summary>
        /// Populates the User with Passwords and Settings.
        /// </summary>
        /// <param name="user">User to be populated.</param>
        /// <returns>User: User with its Passwords and Settings.</returns>
        public User PopulateUserData(User user)
        {
            if (ValidationService.Instance().User(user))
            {
                user.Passwords = CryptoService.Instance().DecryptUserPasswords(user, PasswordsData.Instance().GetUserPasswords(user));
                //user.Settings = (SettingsData.Instance().GetUserSettings(user) == null) ? Globals.Defaults.Settings : SettingsData.Instance().GetUserSettings(user);
                user.Settings = SettingsData.Instance().GetUserSettings(user);
                user.Settings.PasswordOptions = PasswordOptionsData.Instance().GetPasswordOptionsBySettings(user.Settings);

                return(user);
            }
            else
            {
                return(null);
            }
        }
 /// <summary>
 /// Saves a new Password for the supplied User
 /// </summary>
 /// <param name="settings">Settings the Password is to be updated.</param>
 /// <param name="password">Password to be saved.</param>
 /// <returns>Password: The newly saved Password.</returns>
 public Task <Password> SaveNewPasswordAsync(Settings settings, Password password)
 {
     return(Task.Factory.StartNew(() =>
     {
         try
         {
             if (ValidationService.Instance().Password(password))
             {
                 var encryptedPassword = CryptoService.Instance().EncryptPassword(settings.Master, password);
                 PasswordsData.Instance().SaveNewPassword(encryptedPassword);
                 return password;
             }
         }
         catch (Exception)
         { }
         return null;
     }));
 }
 /// <summary>
 /// Removes Password from the Supplied User.
 /// </summary>
 /// <param name="password">Password to be removed.</param>
 /// <returns>Boolean: True if Password Deleted otherwise False.</returns>
 public Task <bool> RemovePasswordAsync(Password password)
 {
     return(Task.Factory.StartNew(() =>
     {
         try
         {
             if (ValidationService.Instance().Password(password))
             {
                 // No need for decrypting password. We only need ID in the Delete method for work
                 PasswordsData.Instance().DeletePassword(password);
                 return true;
             }
         }
         catch (Exception)
         { }
         return false;
     }));
 }
 /// <summary>
 /// Updates the supplied List of Passwords.
 /// </summary>
 /// <param name="user">User for whom the Password is to be updated.</param>
 /// <param name="passwords">List of Passwords to be updated.</param>
 /// <returns>List of Password: The updated passwords.</returns>
 public Task <List <Password> > UpdateUserPasswordsAsync(User user, List <Password> passwords)
 {
     return(Task.Factory.StartNew(() =>
     {
         if (ValidationService.Instance().User(user) && ValidationService.Instance().Passwords(passwords))
         {
             if (PasswordsData.Instance().UpdateUserPasswords(user, CryptoService.Instance().EncryptUserPasswords(user, passwords)) > 0)
             {
                 return passwords;
             }
             else
             {
                 return null;
             }
         }
         else
         {
             return null;
         }
     }));
 }
 public Task <Reminder> AddNewPasswordReminderAsync(Reminder reminder)
 {
     return(Task.Factory.StartNew(() =>
     {
         if (ValidationService.Instance().Password(reminder.ReminderPassword))
         {
             if (PasswordsData.Instance().AddReminderPassword(reminder) > 0)
             {
                 return reminder;
             }
             else
             {
                 return null;
             }
         }
         else
         {
             return null;
         }
     }));
 }
 /// <summary>
 /// Saves a new Password for the supplied User
 /// </summary>
 /// <param name="user">User for whom Password is to be stored.</param>
 /// <param name="password">Password to be saved.</param>
 /// <returns>Password: The newly saved Password.</returns>
 public Task <Password> SaveNewUserPasswordAsync(User user, Password password)
 {
     return(Task.Factory.StartNew(() =>
     {
         if (ValidationService.Instance().User(user) && ValidationService.Instance().Password(password))
         {
             if (PasswordsData.Instance().SaveNewUserPassword(user, CryptoService.Instance().EncryptUserPassword(user, password)) > 0)
             {
                 return password;
             }
             else
             {
                 return null;
             }
         }
         else
         {
             return null;
         }
     }));
 }
 /// <summary>
 /// Removes Password from the Supplied User.
 /// </summary>
 /// <param name="user">User for whom Password is to be removed.</param>
 /// <param name="password">Password to be removed.</param>
 /// <returns>Boolean: True if Password Deleted otherwise False.</returns>
 public Task <bool> RemoveUserPasswordAsync(User user, Password password)
 {
     return(Task.Factory.StartNew(() =>
     {
         if (ValidationService.Instance().User(user) && ValidationService.Instance().Password(password))
         {
             /* No need for decrypting password. We only need ID in the Delete method for work */
             if (PasswordsData.Instance().DeleteUserPassword(user, password) > 0)
             {
                 return true;
             }
             else
             {
                 return false;
             }
         }
         else
         {
             return false;
         }
     }));
 }
        /// <summary>
        /// Gets All Passwords for the Supplied User.
        /// </summary>
        /// <param name="settings">Settings the Password is to be updated.</param>
        /// <returns>List of Passwords for the supplied User.</returns>
        public List <Password> GetAllPasswords(Settings settings)
        {
            List <Password> passwords = PasswordsData.Instance().GetPasswords();

            if (passwords != null)
            {
                passwords = CryptoService.Instance().DecryptPasswords(settings.Master, passwords);

                if (ValidationService.Instance().Passwords(passwords))
                {
                    return(passwords);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Populates the User with Passwords and Settings.
        /// </summary>
        /// <param name="user">User to be populated.</param>
        /// <returns>User: User with its Passwords and Settings.</returns>
        public Task <User> PopulateUserDataAsync(User user)
        {
            return(Task.Factory.StartNew(() =>
            {
                if (ValidationService.Instance().User(user))
                {
                    user.Passwords = CryptoService.Instance().DecryptUserPasswords(user, PasswordsData.Instance().GetUserPasswords(user));
                    user.Settings = SettingsData.Instance().GetUserSettings(user);
                    user.Settings.PasswordOptions = PasswordOptionsData.Instance().GetPasswordOptionsBySettings(user.Settings);

                    return user;
                }
                else
                {
                    return null;
                }
            }));
        }