private async Task <AccountConfiguration> Login(IUserNameCredentials credentials) { var passwordHash = credentials.GetPasswordHash(); var account = storageManager.GetAccount(credentials.UserName, passwordHash); if (account == null) { account = await CreateAccount(credentials.UserName, passwordHash); return(account); } else { return(account); } }
private void ValidateCredentials(IUserNameCredentials credentials) { if (string.IsNullOrWhiteSpace(credentials.UserName)) { throw new Exception("User name should be set"); } if (credentials.UserName.Length < 3) { throw new Exception($"User name length cannot be less than 3"); } if (credentials.Password == null) { throw new Exception($"Password should be set"); } if (credentials.Password.Length < 4) { throw new Exception("Password length cannot be less than 4"); } }
public static string GetPasswordHash(this IUserNameCredentials credentials) { var passwordHash = Security.EncryptPassword(credentials.Password.GetString(), ""); return(passwordHash); }
private async Task CreateWalletAsync(IUserNameCredentials credentials) { var oldView = this.View; var createWalletModel = new CreateWalletModel(); this.View = createWalletModel; try { var wallet = await createWalletModel.CreateWallet(); var syncContent = await syncModel.EnterSync(); try { syncContent.SetTextView("Your wallet is almost ready. We are creating the first address for you."); var tabItem = new Models.TabItem() { Name = wallet.Name, IsSelected = false, }; var walletProvider = new Iota.IotaWalletManager(wallet, tabItem); await walletProvider.EnsureFirstAddressAsync(); if (wallet.IsImported) { walletProvider.InitializeAsync(true); } var passwordHash = credentials.GetPasswordHash(); storageManager.SaveWallet(credentials.UserName, passwordHash, wallet); tabItem.Selected = (t) => View = walletProvider.Wallet; Header.TabItems.Add(tabItem); foreach (var tab in Header.TabItems) // don't know why but need { tab.IsSelected = false; } tabItem.IsSelected = true; return; } catch (OperationCanceledException) { // do nothing } catch (Exception e) { await syncContent.SetCancelView(e.Message).WaitAsync(); } finally { syncContent.Dispose(); } } catch (OperationCanceledException) { // do nothing } this.View = oldView; }