private async void btnLogin_Clicked(object sender, EventArgs e) { if (string.IsNullOrEmpty(entEmail.Text) || string.IsNullOrEmpty(entPassword.Text)) { await DisplayAlert("Error", "Email and Password fields are required", "Ok").ConfigureAwait(false); return; } var user = await this.accountRepository.GetUser(entEmail.Text).ConfigureAwait(false); if (user == null || (user.Password != PasswordUtility.EncryptPassword(entPassword.Text, user.PasswordHash).Key)) { await DisplayAlert("Error", "Incorrect email or password", "Ok").ConfigureAwait(false); return; } Preferences.Set("userId", user.Id); Preferences.Set("fullName", $"{user.FirstName} {user.LastName}"); Preferences.Set("email", user.Email); this.viewModel.IsLoggedIn = true; this.viewModel.DisplayName = $"{user.FirstName} {user.LastName}"; Application.Current.MainPage = new MainPage(); }
public CommonOperationStatus CreateAccount(Account account, bool isSaveChange = true) { if (account.CreatedTime == DateTime.MinValue) { account.CreatedTime = DateTime.Now; } if (account.UpdatedTime == DateTime.MinValue) { account.UpdatedTime = DateTime.Now; } account.Id = Guid.NewGuid(); account.UserId = Guid.NewGuid(); account.Password = PasswordUtility.EncryptPassword(account.Password); _unitOfWork.AccountRepository.Insert(account); if (isSaveChange) { _unitOfWork.Save(); } return(CommonOperationStatus.Success); }
public async Task <int?> CreateUser(User user) { user.PasswordHash = PasswordUtility.EncryptPassword(user.Password, _appSettings.HashIterations); return(await _userRepo.CreateUser(user)); }