public static bool SavePhoneAsync(TLString phone, TLPassword password, IMTProtoService mtProtoService, Action <TLSecureValue> callback, Action <TLRPCError> faultCallback = null) { if (password == null) { return(false); } var passwordSettings = password.Settings as TLPasswordSettings83; if (passwordSettings == null) { return(false); } var inputSecureValue = new TLInputSecureValue85 { Flags = new TLInt(0), Type = new TLSecureValueTypePhone(), PlainData = new TLSecurePlainPhone { Phone = phone } }; var secureSecretId = passwordSettings.SecureSettings.SecureSecretId; mtProtoService.SaveSecureValueAsync( inputSecureValue, secureSecretId, callback.SafeInvoke, faultCallback.SafeInvoke); return(true); }
private static void ResetSecureSecret( TLPasswordSettings passwordSettings, TLPassword passwordBase, TLString password, TLAuthorizationForm authorizationForm, IList <TLSecureValue> secureValues, IMTProtoService mtProtoService, IStateService stateService, INavigationService navigationService) { var passwordSettings83 = passwordSettings as TLPasswordSettings83; if (passwordSettings83 == null) { return; } var password84 = passwordBase as TLPassword84; if (password84 == null) { return; } var newSecureSettings = new TLSecureSecretSettings { SecureAlgo = new TLSecurePasswordKdfAlgoUnknown(), SecureSecret = TLString.Empty, SecureSecretId = new TLLong(0) }; var newSettings = new TLPasswordInputSettings83 { Flags = new TLInt(0), NewSecureSettings = newSecureSettings, }; mtProtoService.GetPasswordAsync( resul1 => { var srpParams = resul1 as IPasswordSRPParams; if (srpParams == null) { return; } var currentPasswordHash = passwordBase.CurrentPasswordHash ?? TLString.Empty; mtProtoService.UpdatePasswordSettingsAsync(SRP.GetCheck(currentPasswordHash, srpParams.SRPId, srpParams.SRPB, srpParams.CurrentAlgo), newSettings, result2 => { passwordSettings83.SecureSettings = newSettings.NewSecureSettings; NavigateToPassportCommon( passwordSettings83, passwordBase, password, authorizationForm, secureValues, mtProtoService, stateService, navigationService); }, error2 => { }); }, error1 => { }); }
public EnterPasswordViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator) { _passwordBase = StateService.Password as TLPassword; if (_passwordBase != null) { PasswordHint = _passwordBase.Hint.ToString(); } }
protected PasswordViewModelBase(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator) { PasswordBase = StateService.Password as TLPassword; if (PasswordBase != null) { PasswordHint = !TLString.IsNullOrEmpty(PasswordBase.Hint) ? PasswordBase.Hint.ToString() : string.Empty; } }
public PasswordRecoveryViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator) { _passwordBase = StateService.Password as TLPassword; StateService.Password = null; if (_passwordBase != null) { PasswordRecoveryHint = string.Format(AppResources.PasswordRecoveryHint, _passwordBase.EmailUnconfirmedPattern); HavingTroubleHint = string.Format(AppResources.HavingTroubleAccessingEmailMessage, _passwordBase.EmailUnconfirmedPattern); } }
//Code from TG or SMS, hash from RequestCodeAsync public async Task MakeAuthAsync(string code, string passHash) { try { await client.MakeAuthAsync(User.Phone, passHash, code); } catch (TLSharp.Core.Exceptions.CloudPasswordNeededException) { TLPassword tLPassword = await client.GetPasswordSetting(); await client.MakeAuthWithPasswordAsync(tLPassword, User.Password); } }
public async Task EnterCodeAsync(string code) { try { CurrentUser = await _client.MakeAuthAsync(_phoneNumber, _loginHash, code); } catch (CloudPasswordNeededException) { _cloudPassword = await _client.GetPasswordSetting(); throw new PasswordRequiredException(); } catch (InvalidPhoneCodeException e) { throw new Exception(e.Message); } }
public async Task <TLUser> MakeAuthWithPasswordAsync(TLPassword password, string password_str) { byte[] password_Bytes = Encoding.UTF8.GetBytes(password_str); IEnumerable <byte> rv = password.CurrentSalt.Concat(password_Bytes).Concat(password.CurrentSalt); SHA256Managed hashstring = new SHA256Managed(); var password_hash = hashstring.ComputeHash(rv.ToArray()); var request = new TLRequestCheckPassword() { PasswordHash = password_hash }; await RequestWithDcMigration(request); OnUserAuthenticated(((TLUser)request.Response.User)); return((TLUser)request.Response.User); }
public ConfirmPasswordViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator) { _password = StateService.Password as TLPassword; StateService.Password = null; if (_password != null) { PasswordHint = _password.Hint.ToString(); } PropertyChanged += (sender, args) => { if (Property.NameEquals(args.PropertyName, () => Code)) { NotifyOfPropertyChange(() => CanConfirm); } }; }
public async Task <TLUser> MakeAuthWithPasswordAsync(TLPassword password, string password_str, CancellationToken token = default(CancellationToken)) { token.ThrowIfCancellationRequested(); byte[] password_Bytes = Encoding.UTF8.GetBytes(password_str); IEnumerable <byte> rv = password.CurrentSalt.Concat(password_Bytes).Concat(password.CurrentSalt); SHA256Managed hashstring = new SHA256Managed(); var password_hash = hashstring.ComputeHash(rv.ToArray()); var request = new TLRequestCheckPassword() { PasswordHash = password_hash }; await RequestWithDcMigration(request, token).ConfigureAwait(false); OnUserAuthenticated((TLUser)request.Response.User); return((TLUser)request.Response.User); }
public async Task <TLUser> MakeAuthWithPasswordAsync(TLPassword password, string password_str) { byte[] password_bytes = Encoding.UTF8.GetBytes(password_str); IEnumerable <byte> rv = password.current_salt.Concat(password_bytes).Concat(password.current_salt); SHA256Managed hashstring = new SHA256Managed(); var password_hash = hashstring.ComputeHash(rv.ToArray()); var request = new TLRequestCheckPassword() { password_hash = password_hash }; await SendRpcRequest(request); //await _sender.Receive(request); OnUserAuthenticated(((TLUser)request.Response.user)); return((TLUser)request.Response.user); }
public async Task <TLUser> MakeAuthWithPasswordAsync(TLPassword password, string password_str, CancellationToken token = default(CancellationToken)) { throw new NotImplementedException(); }
public void Confirm() { if (_password == null) { return; } if (!CanConfirm) { return; } var password84 = _password as TLPassword84; if (password84 == null) { return; } var algo = password84.CurrentAlgo as TLPasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow; if (algo == null) { return; } IsWorking = true; #if LOG_REGISTRATION TLUtils.WriteLog("auth.checkPassword"); #endif BeginOnThreadPool(() => { //var passwordHash = Utils.Password.GetHash(_password.CurrentSalt, new TLString(Code)); var passwordHash = SRP.GetX(new TLString(Code), algo); var password = SRP.GetCheck(passwordHash, password84.SRPId, password84.SRPB, algo); MTProtoService.CheckPasswordAsync( password, auth => BeginOnUIThread(() => { #if LOG_REGISTRATION TLUtils.WriteLog("auth.checkPassword result " + auth); TLUtils.WriteLog("TLUtils.IsLogEnabled=false"); #endif TLUtils.IsLogEnabled = false; TLUtils.LogItems.Clear(); var result = MessageBox.Show( AppResources.ConfirmPushMessage, AppResources.ConfirmPushTitle, MessageBoxButton.OKCancel); if (result != MessageBoxResult.OK) { Notifications.Disable(); } else { Notifications.Enable(); } ConfirmViewModel.UpdateNotificationsAsync(MTProtoService, StateService); MTProtoService.SetInitState(); StateService.CurrentUserId = auth.User.Index; StateService.FirstRun = true; SettingsHelper.SetValue(Constants.IsAuthorizedKey, true); ShellViewModel.Navigate(NavigationService); IsWorking = false; }), error => BeginOnUIThread(() => { #if LOG_REGISTRATION TLUtils.WriteLog("auth.checkPassword error " + error); #endif IsWorking = false; if (error.TypeEquals(ErrorType.PASSWORD_HASH_INVALID)) { MTProtoService.GetPasswordAsync( result1 => BeginOnUIThread(() => { _password = result1 as TLPassword84; MessageBox.Show(AppResources.PasswordInvalidString, AppResources.Error, MessageBoxButton.OK); }), error1 => BeginOnUIThread(() => { MessageBox.Show(AppResources.PasswordInvalidString, AppResources.Error, MessageBoxButton.OK); })); } else if (error.CodeEquals(ErrorCode.FLOOD)) { MessageBox.Show(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.SRP_ID_INVALID)) { IsWorking = true; MTProtoService.GetPasswordAsync( result1 => BeginOnUIThread(() => { IsWorking = false; _password = result1 as TLPassword84; Confirm(); }), error1 => BeginOnUIThread(() => { IsWorking = false; })); } else { Execute.ShowDebugMessage("account.checkPassword error " + error); } })); }); }
public static void NavigateToPassportCommon( TLPasswordSettings passwordSettings, TLPassword passwordBase, TLString password, TLAuthorizationForm authorizationForm, IList <TLSecureValue> secureValues, IMTProtoService mtProtoService, IStateService stateService, INavigationService navigationService) { var passwordSettings83 = passwordSettings as TLPasswordSettings83; if (passwordSettings83 == null) { return; } var secureSettings = passwordSettings83.SecureSettings; passwordBase.Settings = passwordSettings83; var password84 = passwordBase as TLPassword84; if (password84 == null) { return; } var algo = password84.CurrentAlgo as TLPasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow; if (algo == null) { return; } //passwordBase.CurrentPasswordHash = Utils.Password.GetHash(passwordBase.CurrentSalt, password); var passwordHash = SRP.GetX(password, algo); passwordBase.CurrentPasswordHash = passwordHash; // create secure_secret if (secureSettings == null || TLString.IsNullOrEmpty(secureSettings.SecureSecret)) { AddSecureSecret(passwordSettings, passwordBase, password, authorizationForm, secureValues, mtProtoService, stateService, navigationService); return; } var values = authorizationForm != null ? authorizationForm.Values : secureValues; if (values == null) { return; } var decrypted = SetSecretAndDecryptSecureValues(passwordSettings83, password, values); if (!decrypted) { Execute.BeginOnUIThread(() => { ShellViewModel.ShowCustomMessageBox( AppResources.PassportDataCorrupted, AppResources.AppName, AppResources.Reset, AppResources.Cancel, dismissed => { if (dismissed == CustomMessageBoxResult.RightButton) { ResetSecureSecret(passwordSettings, passwordBase, password, authorizationForm, secureValues, mtProtoService, stateService, navigationService); values.Clear(); } }); }); return; } stateService.RemoveBackEntry = true; stateService.AuthorizationForm = authorizationForm; stateService.SecureValues = secureValues; stateService.Password = passwordBase; Execute.BeginOnUIThread(() => { if (authorizationForm != null) { navigationService.UriFor <PassportViewModel>().Navigate(); } else if (secureValues != null) { navigationService.UriFor <PassportSettingsViewModel>().Navigate(); } }); }
public void Done() { if (IsWorking) { return; } var password84 = PasswordBase as TLPassword84; if (password84 == null) { return; } var algo = password84.CurrentAlgo as TLPasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow; if (algo == null) { return; } IsWorking = true; BeginOnThreadPool(() => { var passwordHash = SRP.GetX(new TLString(_password), algo); MTProtoService.GetPasswordSettingsAsync(SRP.GetCheck(passwordHash, password84.SRPId, password84.SRPB, algo), result => BeginOnUIThread(() => { IsWorking = false; PasswordViewModel.Password = _password; PasswordBase.CurrentPasswordHash = passwordHash; PasswordBase.Settings = result; OnSucceded(result); }), error => BeginOnUIThread(() => { IsWorking = false; if (error.TypeEquals(ErrorType.PASSWORD_HASH_INVALID)) { MTProtoService.GetPasswordAsync( result1 => BeginOnUIThread(() => { PasswordBase = result1 as TLPassword84; MessageBox.Show(AppResources.PasswordInvalidString, AppResources.Error, MessageBoxButton.OK); }), error1 => BeginOnUIThread(() => { MessageBox.Show(AppResources.PasswordInvalidString, AppResources.Error, MessageBoxButton.OK); })); } else if (error.CodeEquals(ErrorCode.FLOOD)) { MessageBox.Show(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.SRP_ID_INVALID)) { IsWorking = true; MTProtoService.GetPasswordAsync( result1 => BeginOnUIThread(() => { IsWorking = false; PasswordBase = result1 as TLPassword84; Done(); }), error1 => BeginOnUIThread(() => { IsWorking = false; })); } else { Execute.ShowDebugMessage("account.checkPassword error " + error); } })); }); }