コード例 #1
0
        private async void SendExecute()
        {
            if (_passwordBase == null)
            {
                // TODO: ...
                return;
            }

            if (_password == null)
            {
                await TLMessageDialog.ShowAsync("Please enter your password.");

                return;
            }

            var currentSalt = _passwordBase.CurrentSalt;
            var hash        = TLUtils.Combine(currentSalt, Encoding.UTF8.GetBytes(_password), currentSalt);

            var input  = CryptographicBuffer.CreateFromByteArray(hash);
            var hasher = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
            var hashed = hasher.HashData(input);

            CryptographicBuffer.CopyToByteArray(hashed, out byte[] data);

            var response = await LegacyService.CheckPasswordAsync(data);

            if (response.IsSucceeded)
            {
                // TODO: maybe ask about notifications?

                NavigationService.Navigate(typeof(MainPage));
            }
            else
            {
                if (response.Error.TypeEquals(TLErrorType.PASSWORD_HASH_INVALID))
                {
                    //await new MessageDialog(Resources.PasswordInvalidString, Resources.Error).ShowAsync();
                }
                else if (response.Error.CodeEquals(TLErrorCode.FLOOD))
                {
                    //await new MessageDialog($"{Resources.FloodWaitString}\r\n\r\n({result.Error.Message})", Resources.Error).ShowAsync();
                }

                Execute.ShowDebugMessage("account.checkPassword error " + response.Error);
            }
        }