public void ChangeRecoveryEmail() { if (IsWorking) { return; } if (!CanChangeRecoveryEmail) { return; } if (_passwordBase == null) { return; } var currentPasswordHash = _passwordBase is TLPassword ? ((TLPassword)_passwordBase).CurrentPasswordHash : TLString.Empty; TLPasswordInputSettings newSettings; if (_newPasswordSettings != null) { newSettings = _newPasswordSettings; newSettings.Email = new TLString(RecoveryEmail); } else { newSettings = new TLPasswordInputSettings(); newSettings.Email = new TLString(RecoveryEmail); } UpdatePasswordSettings(currentPasswordHash, newSettings); }
public void ChangePassword() { if (!CanChangePassword) { return; } if (_passwordBase == null) { return; } var newSaltData = TLUtils.Combine(_passwordBase.NewSalt.Data, TLLong.Random().ToBytes()); var newSalt = TLString.FromBigEndianData(newSaltData); var sha = new SHA256Managed(); var newPasswordHashData = sha.ComputeHash(TLUtils.Combine(newSalt.Data, new TLString(_password).Data, newSalt.Data)); var newPasswordHash = TLString.FromBigEndianData(newPasswordHashData); var newSettings = new TLPasswordInputSettings { NewSalt = newSalt, NewPasswordHash = newPasswordHash, Hint = TLString.Empty }; _passwordBase.TempNewPassword = Password; StateService.Password = _passwordBase; StateService.NewPasswordSettings = newSettings; StateService.RemoveBackEntry = true; NavigationService.UriFor <ChangePasswordHintViewModel>().Navigate(); return; }
public void UpdatePasswordSettingsAsync(TLInputCheckPasswordBase password, TLPasswordInputSettings newSettings, Action <TLBool> callback, Action <TLRPCError> faultCallback = null) { var obj = new TLUpdatePasswordSettings { Password = password, NewSettings = newSettings }; SendInformativeMessage("account.updatePasswordSettings", obj, callback, faultCallback); }
public void UpdatePasswordSettingsAsync(TLString currentPasswordHash, TLPasswordInputSettings newSettings, Action <TLBool> callback, Action <TLRPCError> faultCallback = null) { var obj = new TLUpdatePasswordSettings { CurrentPasswordHash = currentPasswordHash, NewSettings = newSettings }; SendInformativeMessage("account.updatePasswordSettings", obj, callback, faultCallback); }
public ChangePasswordEmailViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator) { _passwordBase = StateService.Password; StateService.Password = null; _newPasswordSettings = StateService.NewPasswordSettings; StateService.NewPasswordSettings = null; }
protected ChangePasswordViewModelBase(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator) { _passwordBase = StateService.Password; StateService.Password = null; _newPasswordSettings = StateService.NewPasswordSettings; StateService.NewPasswordSettings = null; _authorizationForm = StateService.AuthorizationForm; StateService.AuthorizationForm = null; _secureValues = StateService.SecureValues; StateService.SecureValues = null; }
public ChangePasswordHintViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator) { _passwordBase = StateService.Password; StateService.Password = null; _newSettings = StateService.NewPasswordSettings; StateService.NewPasswordSettings = null; if (_passwordBase != null && !string.IsNullOrEmpty(_passwordBase.TempNewPassword) && _passwordBase.TempNewPassword.Length > 2) { PasswordHint = string.Format("{0}{1}{2}", _passwordBase.TempNewPassword[0], new String('*', _passwordBase.TempNewPassword.Length - 2), _passwordBase.TempNewPassword[_passwordBase.TempNewPassword.Length - 1]); } }
protected void UpdatePasswordSettings(TLPassword84 password, TLPasswordInputSettings newSettings) { IsWorking = true; BeginOnThreadPool(() => { MTProtoService.GetPasswordAsync( result1 => { var srpParams = result1 as IPasswordSRPParams; if (srpParams == null) { BeginOnUIThread(() => IsWorking = false); return; } var newSettings83 = newSettings as TLPasswordInputSettings83; if (newSettings83 == null) { return; } // calculate new password hash if password will be changed TLString newPasswordHash = null; var newAlgo = newSettings83.NewAlgo as TLPasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow; if (newAlgo != null) { if (string.IsNullOrEmpty(newSettings83.NewPassword)) { return; } newPasswordHash = SRP.GetX(new TLString(newSettings83.NewPassword), newAlgo); newSettings83.NewPasswordHash = SRP.GetVBytes(new TLString(newSettings83.NewPassword), newAlgo); } var currentPasswordHash = password.CurrentPasswordHash ?? TLString.Empty; MTProtoService.UpdatePasswordSettingsAsync(SRP.GetCheck(currentPasswordHash, srpParams.SRPId, srpParams.SRPB, srpParams.CurrentAlgo), newSettings, result2 => { IsWorking = false; MTProtoService.GetPasswordAsync( result3 => BeginOnUIThread(() => { EventAggregator.Publish(result3); var password84 = result3 as TLPassword84; if (password84 != null) { password84.CurrentPasswordHash = newPasswordHash ?? password84.CurrentPasswordHash; } MessageBox.Show(AppResources.PasswordActive, AppResources.Success, MessageBoxButton.OK); if (password84 != null && (_authorizationForm != null || _secureValues != null)) { MTProtoService.GetPasswordSettingsAsync(SRP.GetCheck(password84.CurrentPasswordHash, password84.SRPId, password84.SRPB, password84.CurrentAlgo), result4 => BeginOnUIThread(() => { Passport.EnterPasswordViewModel.NavigateToPassportCommon( result4, password84, new TLString(PasswordViewModel.TempNewPassword), _authorizationForm, _secureValues, MTProtoService, StateService, NavigationService); }), error4 => BeginOnUIThread(() => { if (error4.TypeEquals(ErrorType.PASSWORD_HASH_INVALID)) { StateService.AuthorizationForm = _authorizationForm; StateService.Password = password84; NavigationService.UriFor <Passport.EnterPasswordViewModel>().WithParam(x => x.RandomParam, Guid.NewGuid().ToString()).Navigate(); } })); } else { StateService.Password = result3; NavigationService.GoBack(); } }), error3 => BeginOnUIThread(() => { Execute.ShowDebugMessage("account.getPassword error " + error3); })); }, error2 => BeginOnUIThread(() => { IsWorking = false; var messageBuilder = new StringBuilder(); //messageBuilder.AppendLine(AppResources.Error); //messageBuilder.AppendLine(); messageBuilder.AppendLine("Method: account.updatePasswordSettings"); messageBuilder.AppendLine("Result: " + error2); if (TLRPCError.CodeEquals(error2, ErrorCode.FLOOD)) { HasError = true; Error = AppResources.FloodWaitString; Telegram.Api.Helpers.Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.FloodWaitString, AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.CodeEquals(error2, ErrorCode.INTERNAL)) { HasError = true; Error = AppResources.ServerError; Telegram.Api.Helpers.Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.ServerError, MessageBoxButton.OK)); } else if (TLRPCError.CodeEquals(error2, ErrorCode.BAD_REQUEST)) { if (TLRPCError.TypeEquals(error2, ErrorType.PASSWORD_HASH_INVALID)) { HasError = true; Error = string.Format("{0} {1}", error2.Code, error2.Message); Telegram.Api.Helpers.Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error2, ErrorType.NEW_PASSWORD_BAD)) { HasError = true; Error = string.Format("{0} {1}", error2.Code, error2.Message); Telegram.Api.Helpers.Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error2, ErrorType.NEW_SALT_INVALID)) { HasError = true; Error = string.Format("{0} {1}", error2.Code, error2.Message); Telegram.Api.Helpers.Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error2, ErrorType.EMAIL_INVALID)) { HasError = true; Error = AppResources.EmailInvalid; Telegram.Api.Helpers.Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.EmailInvalid, AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error2, ErrorType.EMAIL_UNCONFIRMED)) { HasError = false; Error = string.Empty; MTProtoService.GetPasswordAsync( result3 => BeginOnUIThread(() => { IsWorking = false; password = result3 as TLPassword84; if (password != null) { password.CurrentPasswordHash = currentPasswordHash; //EMAIL_UNCONFIRMED - new settings are not active yet } MessageBox.Show(AppResources.CompletePasswordHint, AppResources.AlmostThere, MessageBoxButton.OK); if (_authorizationForm != null || _secureValues != null) { StateService.AuthorizationForm = _authorizationForm; StateService.SecureValues = _secureValues; StateService.Password = result3; StateService.RemoveBackEntry = true; NavigationService.UriFor <PasswordViewModel>().Navigate(); } else { StateService.Password = result3; NavigationService.GoBack(); } }), error3 => Execute.BeginOnUIThread(() => { IsWorking = false; Execute.ShowDebugMessage("account.getPassword error " + error3); })); } else { HasError = true; Error = string.Format("{0} {1}", error2.Code, error2.Message); Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } } else { HasError = true; Error = string.Empty; Execute.ShowDebugMessage("account.updatePasswordSettings error " + error2); } })); }, error1 => BeginOnUIThread(() => { IsWorking = false; })); }); }
private void UpdatePasswordSettings(TLString currentPasswordHash, TLPasswordInputSettings newSettings) { IsWorking = true; MTProtoService.UpdatePasswordSettingsAsync(currentPasswordHash, newSettings, result => { IsWorking = false; MTProtoService.GetPasswordAsync( passwordBase => BeginOnUIThread(() => { var password = passwordBase as TLPassword; if (password != null) { password.CurrentPasswordHash = newSettings.NewPasswordHash; //EMAIL_CONFIRMED, news settings are active already } MessageBox.Show(AppResources.PasswordActive, AppResources.Success, MessageBoxButton.OK); StateService.Password = passwordBase; NavigationService.GoBack(); }), error => Execute.BeginOnUIThread(() => { Execute.ShowDebugMessage("account.getPassword error " + error); })); }, error => { IsWorking = false; var messageBuilder = new StringBuilder(); //messageBuilder.AppendLine(AppResources.Error); //messageBuilder.AppendLine(); messageBuilder.AppendLine("Method: account.updatePasswordSettings"); messageBuilder.AppendLine("Result: " + error); if (TLRPCError.CodeEquals(error, ErrorCode.FLOOD)) { HasError = true; Error = AppResources.FloodWaitString; Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.FloodWaitString, AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.CodeEquals(error, ErrorCode.INTERNAL)) { HasError = true; Error = AppResources.ServerError; Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.ServerError, MessageBoxButton.OK)); } else if (TLRPCError.CodeEquals(error, ErrorCode.BAD_REQUEST)) { if (TLRPCError.TypeEquals(error, ErrorType.PASSWORD_HASH_INVALID)) { HasError = true; Error = string.Format("{0} {1}", error.Code, error.Message); Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.NEW_PASSWORD_BAD)) { HasError = true; Error = string.Format("{0} {1}", error.Code, error.Message); Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.NEW_SALT_INVALID)) { HasError = true; Error = string.Format("{0} {1}", error.Code, error.Message); Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.EMAIL_INVALID)) { HasError = true; Error = AppResources.EmailInvalid; Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.EmailInvalid, AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.EMAIL_UNCONFIRMED)) { HasError = false; Error = " "; Execute.BeginOnUIThread(() => { MTProtoService.GetPasswordAsync( passwordBase => BeginOnUIThread(() => { IsWorking = false; var password = passwordBase as TLPassword; if (password != null) { password.CurrentPasswordHash = currentPasswordHash; //EMAIL_UNCONFIRMED - new settings are not active yet } MessageBox.Show(AppResources.CompletePasswordHint, AppResources.AlmostThere, MessageBoxButton.OK); StateService.Password = passwordBase; NavigationService.GoBack(); }), error2 => Execute.BeginOnUIThread(() => { IsWorking = false; Execute.ShowDebugMessage("account.getPassword error " + error2); })); }); } else { HasError = true; Error = string.Format("{0} {1}", error.Code, error.Message); Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } } else { HasError = true; Error = string.Empty; Execute.ShowDebugMessage("account.updatePasswordSettings error " + error); } }); }
private void ClearPassword() { TLString currentPasswordHash; TLPasswordInputSettings newSettings; var password = _password as TLPassword; if (password != null) { currentPasswordHash = password.CurrentPasswordHash; newSettings = new TLPasswordInputSettings { NewSalt = TLString.Empty, NewPasswordHash = TLString.Empty, Hint = TLString.Empty, Email = TLString.Empty }; } else { currentPasswordHash = TLString.Empty; newSettings = new TLPasswordInputSettings { Email = TLString.Empty }; } IsWorking = true; MTProtoService.UpdatePasswordSettingsAsync(currentPasswordHash, newSettings, result => BeginOnUIThread(() => { StopTimer(); IsWorking = false; _password = new TLNoPassword { NewSalt = _password.NewSalt, EmailUnconfirmedPattern = TLString.Empty }; if (_password != null) { PasswordEnabled = _password.IsAvailable; RecoveryEmailUnconfirmedVisibility = !TLString.IsNullOrEmpty(_password.EmailUnconfirmedPattern) || (_password is TLPassword && ((TLPassword)_password).HasRecovery.Value) ? Visibility.Visible : Visibility.Collapsed; NotifyOfPropertyChange(() => RecoveryEmailLabel); NotifyOfPropertyChange(() => CompletePasswordLabel); NotifyOfPropertyChange(() => ChangePasswordVisibility); NotifyOfPropertyChange(() => CompletePasswordVisibility); } }), error => BeginOnUIThread(() => { IsWorking = false; var messageBuilder = new StringBuilder(); //messageBuilder.AppendLine(AppResources.ServerErrorMessage); //messageBuilder.AppendLine(); messageBuilder.AppendLine("Method: account.updatePasswordSettings"); messageBuilder.AppendLine("Result: " + error); if (TLRPCError.CodeEquals(error, ErrorCode.FLOOD)) { Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.FloodWaitString, AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.CodeEquals(error, ErrorCode.INTERNAL)) { Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.ServerError, MessageBoxButton.OK)); } else if (TLRPCError.CodeEquals(error, ErrorCode.BAD_REQUEST)) { if (TLRPCError.TypeEquals(error, ErrorType.PASSWORD_HASH_INVALID)) { Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.NEW_PASSWORD_BAD)) { Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.NEW_SALT_INVALID)) { Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.EMAIL_INVALID)) { Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.EmailInvalid, AppResources.Error, MessageBoxButton.OK)); } else if (TLRPCError.TypeEquals(error, ErrorType.EMAIL_UNCONFIRMED)) { Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } else { Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK)); } } else { Execute.ShowDebugMessage("account.updatePasswordSettings error " + error); } })); }