public string CalculatePassword(string password) { return(CryptographyHelper.CalculatePasswordMD5Hash(Email, password)); }
public async Task <bool> Connect(string deviceModel , string platform , string version , string uniqueDeviceId , string countryCode) { App.Locator.ListSeekios.IsNotFromLogin = false; if (string.IsNullOrEmpty(Email) || string.IsNullOrEmpty(Password) || string.IsNullOrEmpty(deviceModel) || string.IsNullOrEmpty(version) || string.IsNullOrEmpty(uniqueDeviceId)) { // TODO : handle custom alert msg return(false); } var connectOk = false; IsLoading = true; try { var passHash = Password; passHash = CryptographyHelper.CalculatePasswordMD5Hash(Email, Password); DataService.Email = Email; DataService.Pass = passHash; App.CurrentUserEnvironment = await _dataService.GetUserEnvironment(App.Locator.Login.VersionApplication, platform, deviceModel, version, uniqueDeviceId, countryCode); // The app need an update if (App.CurrentUserEnvironment == null) { RemoveSavedCredentials(); App.IsAppNeedUpdate = true; _navigationService.NavigateTo(App.NEED_UPDATE_PAGE); return(false); } // Authentication failed else if (App.CurrentUserEnvironment.User == null) { return(false); } // Authentication succeeded else { InitTimers(); connectOk = true; } } catch (TimeoutException) { await _dialogService.ShowError( Resources.TimeoutError , Resources.TimeoutErrorTitle , Resources.Close, null); } catch (WebException) { await _dialogService.ShowError( Resources.TimeoutError , Resources.TimeoutErrorTitle , Resources.Close, null); } catch (Exception) { await _dialogService.ShowError( Resources.UnexpectedError , Resources.UnexpectedErrorTitle , Resources.Close, null); } finally { IsLoading = false; } // save data and navigate to seekios list if the user is correctly authenticated if (connectOk) { SaveCurrentCredentials(); if (GetSavedFirstLaunchTuto()) { _navigationService.NavigateTo(App.LIST_SEEKIOS_PAGE); } else { _navigationService.NavigateTo(App.TUTORIAL_BACKGROUND_FIRST_LAUNCH_PAGE); } } Password = string.Empty; AppTimer = ServiceLocator.Current.GetInstance <ITimer>(); return(connectOk); }
public async Task <bool> CreateAccount(string firstName , string lastName , string deviceModel , string platform , string version , string uniqueDeviceId , string countryCode) { if (string.IsNullOrEmpty(UserEmail) || string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(UserPassword) || string.IsNullOrEmpty(deviceModel) || string.IsNullOrEmpty(version) || string.IsNullOrEmpty(uniqueDeviceId)) { return(false); } IsLoading = true; var passHash = CryptographyHelper.CalculatePasswordMD5Hash(UserEmail, UserPassword); try { App.Locator.ListSeekios.IsNotFromLogin = false; // TODO : plus d'infos à récupérer depuis Facebook var user = new UserDTO() { Email = UserEmail, FirstName = firstName, LastName = lastName, Password = passHash, IdCountryResource = ParserHelper.ParseCountryCode(countryCode) }; int result = await _dataService.InsertUser(user); if (result == 1) { user.IdUser = result; } else { IsLoading = false; return(false); } await _dialogService.ShowMessage(Resources.CreateAccountSuccessText , Resources.CreateAccountSuccessTitle); IsLoading = false; Email = UserEmail; Password = UserPassword; return(await Connect(deviceModel, platform, version, uniqueDeviceId, countryCode)); } catch (TimeoutException) { await _dialogService.ShowError( Resources.TimeoutError , Resources.TimeoutErrorTitle , Resources.Close, null); } catch (WebException) { await _dialogService.ShowError( Resources.TimeoutError , Resources.TimeoutErrorTitle , Resources.Close, null); } catch (Exception) { await _dialogService.ShowError( Resources.UnexpectedError , Resources.UnexpectedErrorTitle , Resources.Close, null); } return(false); }
/// <summary> /// Update user password in database /// </summary> public async Task <bool> UpdateNewPasswordChanged() { var previousPassword = string.Empty; try { IsUpdating = true; var hash = CryptographyHelper.CalculatePasswordMD5Hash(App.CurrentUserEnvironment.User.Email, OldPassword); if (App.CurrentUserEnvironment.User.Password != hash) { var msg = Resources.BadPassword; var title = Resources.BadPasswordTitle; await _dialogService.ShowMessage(msg, title); IsUpdating = false; return(false); } if (NewPassword != NewPasswordReenter) { var msg = Resources.PasswordDoesntMatch; var title = Resources.PasswordDoesntMatchTitle; await _dialogService.ShowMessage(msg, title); IsUpdating = false; return(false); } if (NewPassword.Length < 6) { //var msg = Resources.PasswordTooShort; //var title = Resources.PasswordTooShortTitle; //await _dialogService.ShowMessage(msg, title); IsUpdating = false; return(false); } previousPassword = App.CurrentUserEnvironment.User.Password; App.CurrentUserEnvironment.User.Password = CryptographyHelper.CalculatePasswordMD5Hash(App.CurrentUserEnvironment.User.Email, NewPassword); if (await _dataService.UpdateUser(App.CurrentUserEnvironment.User) >= 1) { // Save new password for auto reconnection App.Locator.Login.SaveCurrentCredentials(); DataService.Pass = App.CurrentUserEnvironment.User.Password; await _dialogService.ShowMessage(Resources.PasswordUpdated, Resources.PasswordUpdateTitle); } else { App.CurrentUserEnvironment.User.Password = previousPassword; await _dialogService.ShowError(Resources.PasswordUpdateFailed, Resources.PasswordUpdateTitle, Resources.WebErrorButtonText, null); } IsUpdating = false; return(true); } catch (WebException) { App.CurrentUserEnvironment.User.Password = previousPassword; await _dialogService.ShowError(Resources.PasswordUpdateFailed , Resources.PasswordUpdateTitle , Resources.WebErrorButtonText, null); } catch (TimeoutException) { App.CurrentUserEnvironment.User.Password = previousPassword; await _dialogService.ShowError(Resources.PasswordUpdateFailed , Resources.PasswordUpdateTitle , Resources.WebErrorButtonText, null); } App.Locator.Parameter.OldPassword = null; App.Locator.Parameter.NewPassword = null; App.Locator.Parameter.NewPasswordReenter = null; IsUpdating = false; return(false); }