Exemple #1
0
        public override SecureString GetPassword()
        {
            string GetPasswordN(int n, string[] passwordsCollection) => passwordsCollection?.Length > 0 ? passwordsCollection[Math.Min(n, passwordsCollection.Length - 1)] : null;

            SecureString password = null;
            var          keyStoreConfigPasswordIndex = Array.IndexOf(_keyStoreConfig.UnlockAccounts, Account);

            if (keyStoreConfigPasswordIndex >= 0)
            {
                var passwordFile = GetPasswordN(keyStoreConfigPasswordIndex, _keyStoreConfig.PasswordFiles);
                if (passwordFile != null)
                {
                    string passwordFilePath = passwordFile.GetApplicationResourcePath();
                    _filePasswordProvider.FileName = passwordFilePath;
                    password = _filePasswordProvider.GetPassword();
                }

                password ??= GetPasswordN(keyStoreConfigPasswordIndex, _keyStoreConfig.Passwords)?.Secure();
            }

            if (password == null && AlternativeProvider != null)
            {
                password = AlternativeProvider.GetPassword();
            }

            return(password);
        }
        public override SecureString GetPassword(Address address)
        {
            SecureString password = null;
            int          keyStoreConfigPasswordIndex = _keyStoreConfig.FindUnlockAccountIndex(address);

            if (keyStoreConfigPasswordIndex >= 0)
            {
                password = _filePasswordProvider.GetPassword(address);
                password ??= GetNthOrLast(keyStoreConfigPasswordIndex, _keyStoreConfig.Passwords)?.Secure();
            }

            if (password == null && AlternativeProvider != null)
            {
                password = AlternativeProvider.GetPassword(address);
            }

            return(password);
        }