Example #1
0
        public bool TryCreateSafeForExistingUser(string userName, string password, out ISafe safe)
        {
            var account = AccountGateway.ReadUserAccount(WorkingDirectory, userName);
            var verifyingWordBytesForCurrentPassword = Cryptor.GetEncryptedBytes(account.VerifyingWord, password);

            try
            {
                var masterPassword = Cryptor.GetDecryptedContent <string>(account.MasterEncryptedPassBytes, password);
                safe = null;

                if (account.VeryifyingWordEncryptedBytes.Length != verifyingWordBytesForCurrentPassword.Length)
                {
                    return(false);
                }
                for (var i = 0; i < account.VeryifyingWordEncryptedBytes.Length; i++)
                {
                    if (account.VeryifyingWordEncryptedBytes[i] != verifyingWordBytesForCurrentPassword[i])
                    {
                        return(false);
                    }
                }
                safe                  = new Safe(masterPassword);
                safe.UserName         = userName;
                safe.WorkingDirectory = WorkingDirectory;
                return(true);
            }
            catch (Exception e)
            {
                safe = null;
                return(false);
            }
        }