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 void SignUp() { var result = MessageBox.Show( AppResources.ConfirmAgeMessage, AppResources.ConfirmAgeTitle, MessageBoxButton.OKCancel); if (result != MessageBoxResult.OK) { return; } IsWorking = true; NotifyOfPropertyChange(() => CanSignUp); MTProtoService.SignUpAsync( StateService.PhoneNumber, StateService.PhoneCodeHash, StateService.PhoneCode, new TLString(FirstName), new TLString(LastName), auth => BeginOnUIThread(() => { TLUtils.IsLogEnabled = false; TLUtils.LogItems.Clear(); 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; NotifyOfPropertyChange(() => CanSignUp); if (StateService.ProfilePhotoBytes != null) { var bytes = StateService.ProfilePhotoBytes; StateService.ProfilePhotoBytes = null; var fileId = TLLong.Random(); FileManager.UploadFile(fileId, new TLUser66 { IsSelf = true }, bytes); } }), error => BeginOnUIThread(() => { IsWorking = false; NotifyOfPropertyChange(() => CanSignUp); if (error.TypeEquals(ErrorType.PHONE_NUMBER_INVALID)) { MessageBox.Show(AppResources.PhoneNumberInvalidString, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.PHONE_CODE_INVALID)) { MessageBox.Show(AppResources.PhoneCodeInvalidString, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.PHONE_CODE_EMPTY)) { MessageBox.Show(AppResources.PhoneCodeEmpty, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.PHONE_CODE_EXPIRED)) { MessageBox.Show(AppResources.PhoneCodeExpiredString, AppResources.Error, MessageBoxButton.OK); ClearViewModel(); NavigationService.GoBack(); } else if (error.CodeEquals(ErrorCode.FLOOD)) { MessageBox.Show(AppResources.FloodWaitString, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.FIRSTNAME_INVALID)) { MessageBox.Show(AppResources.FirstNameInvalidString, AppResources.Error, MessageBoxButton.OK); } else if (error.TypeEquals(ErrorType.LASTNAME_INVALID)) { MessageBox.Show(AppResources.LastNameInvalidString, AppResources.Error, MessageBoxButton.OK); } else { Telegram.Api.Helpers.Execute.ShowDebugMessage("auth.signUp error " + error); } })); }