public string AddUser(AccountPassword accountPassword) { var guid = Guid.NewGuid().ToString(); _authenticatedTokens.Add(guid, accountPassword.Account.Id); return(guid); }
private async Task GenerateAccountPasswordAsync() { try { if (LdapSettings?.Password == null) { throw new Exception("Active Directory credentials not set in parameters page."); } var accountPassword = new AccountPassword() { Password = PasswordGenerator.Generate() }; using (TransactionScope transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { await EmployeeService.EditPersonalAccountPwdAsync(Account, accountPassword); await LdapService.SetUserPasswordAsync(Account.EmployeeId, accountPassword.Password, LdapSettings); transactionScope.Complete(); } RemoteDeviceConnectionsService.StartUpdateHardwareVaultAccounts(await EmployeeService.GetEmployeeVaultIdsAsync(Account.EmployeeId)); await ToastService.ShowToastAsync("Account password updated.", ToastType.Success); await ModalDialogClose(); } catch (Exception ex) { Logger.LogError(ex.Message); await ToastService.ShowToastAsync(ex.Message, ToastType.Error); await ModalDialogCancel(); } }
public override List <ErrorType> GetErrors() { List <ErrorType> list = base.GetErrors(); if (AccountName.NullOrEmpty() || AccountName == CONSTANTS.INVALID) { list.Add(ErrorType.AccountName); } if (AccountPassword.NullOrEmpty() || AccountPassword == CONSTANTS.INVALID) { list.Add(ErrorType.AccountPassword); } if (StartTime == null || StartTime == CONSTANTS.INVALID_DATE) { list.Add(ErrorType.StartTime); } if (AssessmentLength <= 0) { list.Add(ErrorType.AssessmentLength); } if (ReadingTime < 0) { list.Add(ErrorType.ReadingTime); } return(list); }
public List <ErrorType> GetErrors(string deployTarget) { List <ErrorType> list = base.GetErrors(); if (AccountName.NullOrEmpty() || !Directory.Exists(Path.Combine(deployTarget, AccountName))) { list.Add(ErrorType.AccountName); } if (AccountPassword.NullOrEmpty() || AccountPassword == CONSTANTS.INVALID) { list.Add(ErrorType.AccountPassword); } if (StartTime == null || StartTime == CONSTANTS.INVALID_DATE) { list.Add(ErrorType.StartTime); } if (AssessmentLength <= 0) { list.Add(ErrorType.AssessmentLength); } if (ReadingTime < 0) { list.Add(ErrorType.ReadingTime); } return(list); }
public void パスワードの要件が満たせている() { const string password = "******"; var accountPassword = new AccountPassword(password); Assert.AreEqual(password, accountPassword.Value); }
public static async Task <IActionResult> UpdatePassword( [HttpTrigger(AuthorizationLevel.Function, "put", Route = "passwords/{id}")] HttpRequest req, [CosmosDB( databaseName: "%COSMOS_DATABASENAME%", collectionName: "%COSMOS_COLLECTIONNAME%", PartitionKey = "%COSMOS_PARTITIONKEY%", ConnectionStringSetting = "cosmosdb", Id = "{id}")] AccountPassword accountPassword, ILogger log) { if (accountPassword.isDeleted == true) { log.LogInformation($"UpdatePassword Request received for {accountPassword.id} but document is marked deleted"); return((ActionResult) new OkObjectResult(null)); } log.LogInformation($"UpdatePassword request for {accountPassword.id}"); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); AccountPassword updates = JsonConvert.DeserializeObject <AccountPassword>(requestBody); accountPassword.SiteName = updates.SiteName; accountPassword.AccountName = updates.AccountName; accountPassword.Notes = updates.Notes; accountPassword.SecurityQuestions = updates.SecurityQuestions; accountPassword.UpdatePassword(e, updates.CurrentPassword, accountPassword.LastModifiedDate); accountPassword.LastModifiedDate = DateTime.Now; return((ActionResult) new OkObjectResult(accountPassword)); }
public AccountCreationResponse CreateAccount(QuickCreationInfo quickAccountCreationInfo) { if (!_validator.IsDisplayNameValid(quickAccountCreationInfo.DisplayName)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = "display name is invalid" }); } var randomString = Guid.NewGuid().ToString(); string fakeEmail = string.Empty; string fakePassword = randomString; var account = new Account(0, quickAccountCreationInfo.DisplayName, fakeEmail, AccountType.Quick); var defaultState = TimeWarpUserState.DefaultState(account); var accountPassword = new AccountPassword(account, fakePassword); //save _accountRepository.Add(account); _passwordRepository.Add(accountPassword); _userStateRepository.Add(defaultState); string token = _authenticationManager.AddUser(accountPassword); if (Log.IsDebugEnabled) { Log.DebugFormat("account created for {0}", randomString); } return(new AccountCreationResponse(account.Id, token)); }
public async Task <IActionResult> EditAccountPassword(string id, EditAccountPasswordDto accountDto) { if (id != accountDto.Id) { return(BadRequest()); } try { var account = await _employeeService.GetAccountByIdAsync(id); if (account == null) { return(BadRequest("Account not found.")); } var accountPassword = new AccountPassword() { Password = accountDto.Password }; await _employeeService.EditPersonalAccountPwdAsync(account, accountPassword); _remoteDeviceConnectionsService.StartUpdateHardwareVaultAccounts(await _employeeService.GetEmployeeVaultIdsAsync(account.EmployeeId)); } catch (Exception ex) { _logger.LogError(ex.Message); return(StatusCode(500, new { error = ex.Message })); } return(NoContent()); }
public async Task <IActionResult> EditSharedAccountPassword(string id, EditSharedAccountPasswordDto sharedAccountDto) { if (id != sharedAccountDto.Id) { return(BadRequest()); } try { var sharedAccount = await _sharedAccountService.GetSharedAccountByIdAsync(id); var accountPassword = new AccountPassword() { Password = sharedAccountDto.Password }; var vaultIds = await _sharedAccountService.EditSharedAccountPwdAsync(sharedAccount, accountPassword); _remoteDeviceConnectionsService.StartUpdateHardwareVaultAccounts(vaultIds); } catch (Exception ex) { _logger.LogError(ex.Message); return(StatusCode(500, new { error = ex.Message })); } return(NoContent()); }
private async void LoginButton_OnClick(object sender, RoutedEventArgs e) { if (AccountAddress.Text != "" && AccountPassword.Password != "") { AccountAddress.IsEnabled = false; AccountPassword.IsEnabled = false; LoginButton.IsEnabled = false; string username = AccountAddress.Text; string password = AccountPassword.Password; if (await DropAccount.Login(username, password)) { DialogResult = true; } else { AccountAddress.Clear(); AccountPassword.Clear(); } AccountAddress.IsEnabled = true; AccountPassword.IsEnabled = true; LoginButton.IsEnabled = true; } else { MessageBox.Show("Заполните все поля!", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning); } }
/// <summary> /// Login to the application. /// </summary> /// <returns>The result.</returns> public LoginResultDto Login() { this.SetResponseHeaderCacheExpiration(); AccountPassword credentials = this.GetCredentialsFromRequest(); AccountServerService service = new AccountServerService(); return(service.Login(credentials.Account, credentials.Password)); }
public string AddUser(AccountPassword accountPassword) { var token = _sessionIdProvider.GetSessionId(); var authenticationSession = new AuthenticationSession(accountPassword.Account, token, _nowProvider.Now); _authenticationSessionRepository.Add(authenticationSession); return(token); }
/// <summary> /// Updates a lesson. /// </summary> /// <param name="itemToSave">The item to save.</param> /// <returns></returns> public ResultDto UpdateLesson(LessonEditDto itemToSave) { this.SetResponseHeaderCacheExpiration(); AccountPassword credentials = this.GetCredentialsFromRequest(); AccountServerService accountService = new AccountServerService(); Guid accountId = accountService.GetAccountId(credentials.Account); LessonServerService service = new LessonServerService(); return(service.InsertUpdateLesson(itemToSave, accountId)); }
/// <summary> /// Returns the lessons of a week. /// </summary> /// <returns>The lessons.</returns> public List <LessonEditDto> GetLessonOfWeek() { this.SetResponseHeaderCacheExpiration(); AccountPassword credentials = this.GetCredentialsFromRequest(); AccountServerService accountService = new AccountServerService(); Guid accountId = accountService.GetAccountId(credentials.Account); LessonServerService service = new LessonServerService(); return(service.GetLessonsOfWeek(accountId)); }
/// <summary> /// Returns the lesson of a day to display. /// </summary> /// <param name="id">The day identifier.</param> /// <returns>The lessons.</returns> public List <LessonDisplayDto> GetLessonOfDayToDisplay(string id) { this.SetResponseHeaderCacheExpiration(); AccountPassword credentials = this.GetCredentialsFromRequest(); AccountServerService accountService = new AccountServerService(); Guid accountId = accountService.GetAccountId(credentials.Account); LessonServerService service = new LessonServerService(); return(service.GetLessonsOfDayToDisplay(new Guid(id), accountId)); }
/// <summary> /// Returns the room lookup. /// </summary> /// <returns>The room lookup.</returns> public List <RoomLookupDto> GetRoomLookup() { this.SetResponseHeaderCacheExpiration(); AccountPassword credentials = this.GetCredentialsFromRequest(); AccountServerService accountService = new AccountServerService(); Guid accountId = accountService.GetAccountId(credentials.Account); RoomServerService service = new RoomServerService(); return(service.GetRoomLookup(accountId)); }
/// <summary> /// Deletes a lesson. /// </summary> /// <param name="idToDelete">The identifier.</param> /// <returns>The result.</returns> public ResultDto DeleteLesson(IdDto idToDelete) { this.SetResponseHeaderCacheExpiration(); AccountPassword credentials = this.GetCredentialsFromRequest(); AccountServerService accountService = new AccountServerService(); Guid accountId = accountService.GetAccountId(credentials.Account); LessonServerService service = new LessonServerService(); return(service.DeleteLesson(idToDelete.Id, accountId)); }
public async Task EditPersonalAccountPwdAsync(Account account, AccountPassword accountPassword) { if (account == null) { throw new ArgumentNullException(nameof(account)); } if (accountPassword == null) { throw new ArgumentNullException(nameof(accountPassword)); } _dataProtectionService.Validate(); var employee = await GetEmployeeByIdAsync(account.EmployeeId); account.UpdatedAt = DateTime.UtcNow; account.PasswordUpdatedAt = DateTime.UtcNow; // Update password field if there are no vaults if (employee.HardwareVaults.Count == 0) { account.Password = _dataProtectionService.Encrypt(accountPassword.Password); } // Create tasks if there are vaults List <HardwareVaultTask> tasks = new List <HardwareVaultTask>(); foreach (var vault in employee.HardwareVaults) { tasks.Add(_hardwareVaultTaskService.GetAccountPwdUpdateTask(vault.Id, account.Id, _dataProtectionService.Encrypt(accountPassword.Password))); } using (TransactionScope transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { await _accountService.UpdateOnlyPropAsync(account, new string[] { nameof(Account.UpdatedAt), nameof(Account.PasswordUpdatedAt), nameof(Account.Password) }); if (tasks.Count > 0) { await _hardwareVaultTaskService.AddRangeTasksAsync(tasks); await _hardwareVaultService.UpdateNeedSyncAsync(employee.HardwareVaults, true); } transactionScope.Complete(); } }
public AccountCreationResponse CreateAccount(FullAccountCreationInfo fullAccountCreationInfo) { if (!_validator.IsEmailValid(fullAccountCreationInfo.EmailAddress)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = "email address is invalid" }); } if (!_validator.IsDuplicateEmailAddress(fullAccountCreationInfo.EmailAddress)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = "email address is duplicate" }); } if (!_validator.IsDisplayNameValid(fullAccountCreationInfo.DisplayName)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = "display name is invalid" }); } //does email address exist? var account = new Account(0, fullAccountCreationInfo.DisplayName, fullAccountCreationInfo.EmailAddress, AccountType.Full); var defaultState = TimeWarpUserState.DefaultState(account); var accountPassword = new AccountPassword(account, fullAccountCreationInfo.Password); //save _accountRepository.Add(account); _passwordRepository.Add(accountPassword); _userStateRepository.Add(defaultState); string token = _authenticationManager.AddUser(accountPassword); if (Log.IsDebugEnabled) { Log.DebugFormat("account created for {0}", fullAccountCreationInfo.EmailAddress); } return(new AccountCreationResponse(account.Id, token)); }
public static IActionResult GetPasswordById( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "passwords/{id}")] HttpRequest req, [CosmosDB( databaseName: "%COSMOS_DATABASENAME%", collectionName: "%COSMOS_COLLECTIONNAME%", PartitionKey = "%COSMOS_PARTITIONKEY%", ConnectionStringSetting = "cosmosdb", Id = "{id}")] AccountPassword accountPassword, ILogger log) { log.LogInformation($"GetPasswordById request for {accountPassword.id}"); var clone = accountPassword.Clone(); clone.CurrentPassword = clone.DecryptPassword(e); return((ActionResult) new OkObjectResult(clone)); }
public ActionResult Login(HeadHunter.Models.UnifiedModels.LoginModel model, string returnUrl) { if ((model.Account.AccountMail == null) || (model.AccountPassword.AccountPassword1 == null)) { ViewBag.Msg = "Please Enter Your Mail Or Password"; return(View()); } else { Account newAccount = new Account(); AccountPassword newAccountPassword = new AccountPassword(); newAccount = db.Account.FirstOrDefault(m => m.AccountMail == model.Account.AccountMail); if (newAccount == null) { ViewBag.Msg = "Please Enter Your Mail Or Password Correctly!"; return(View()); } newAccountPassword = db.AccountPassword.FirstOrDefault(m => m.AccountId == newAccount.AccountId); //var count = db.Account.Where(x => x.AccountMail == model.Account.AccountMail && x.AccountFullName == model.AccountPassword.AccountPassword1).Count(); if ((model.Account.AccountMail == newAccount.AccountMail) && (model.AccountPassword.AccountPassword1 == newAccountPassword.AccountPassword1)) { FormsAuthentication.SetAuthCookie(model.Account.AccountMail, false); if (newAccount.AccountType == false) { Session.Add("MemberAuth", RoleNames.Employer); Session.Add("UserMail", model.Account.AccountMail); } else { Session.Add("MemberAuth", RoleNames.Employee); Session.Add("UserMail", model.Account.AccountMail); } return(RedirectToLocal(returnUrl)); } else { ViewBag.Msg = "Invalid User"; return(View()); } } }
public static IActionResult DeletePassword( [HttpTrigger(AuthorizationLevel.Function, "delete", Route = "passwords/{id}")] HttpRequest req, [CosmosDB( databaseName: "%COSMOS_DATABASENAME%", collectionName: "%COSMOS_COLLECTIONNAME%", PartitionKey = "%COSMOS_PARTITIONKEY%", ConnectionStringSetting = "cosmosdb", Id = "{id}")] AccountPassword accountPassword, ILogger log) { if (accountPassword.isDeleted == true) { log.LogInformation($"DeletePassword Request received for {accountPassword.id} but document is already marked deleted"); return((ActionResult) new OkObjectResult(null)); } log.LogInformation($"DeletePassword request for {accountPassword.id}"); accountPassword.isDeleted = true; accountPassword.LastModifiedDate = DateTime.Now; return((ActionResult) new OkObjectResult(accountPassword)); }
public static async Task <IActionResult> PostPassword( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "passwords")] HttpRequest req, [CosmosDB( databaseName: "%COSMOS_DATABASENAME%", collectionName: "%COSMOS_COLLECTIONNAME%", ConnectionStringSetting = "cosmosdb")] IAsyncCollector <AccountPassword> passwordCollection, ILogger log) { log.LogInformation($"PostPassword request new account received"); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); AccountPassword accountPassword = JsonConvert.DeserializeObject <AccountPassword>(requestBody); accountPassword.PartitionKey = partitionKey; accountPassword.LastModifiedDate = accountPassword.CreatedDate = DateTime.Now; accountPassword.CurrentPassword = accountPassword.EncryptPassword(e); await passwordCollection.AddAsync(accountPassword); return((ActionResult) new OkObjectResult(accountPassword)); }
public static IActionResult GetPasswordHistoryById( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "passwords/{id}/history")] HttpRequest req, [CosmosDB( databaseName: "%COSMOS_DATABASENAME%", collectionName: "%COSMOS_COLLECTIONNAME%", PartitionKey = "%COSMOS_PARTITIONKEY%", ConnectionStringSetting = "cosmosdb", Id = "{id}")] AccountPassword accountPassword, ILogger log) { log.LogInformation($"GetPasswordHistoryById request for {accountPassword.id}"); var history = new List <PasswordTrail>(); var currentPassword = new PasswordTrail() { SiteName = accountPassword.SiteName, Password = accountPassword.DecryptPassword(e), TimeStamp = accountPassword.CreatedDate }; history.Add(currentPassword); if (accountPassword.OldPasswords != null) { var oldPasswords = from oldPassword in accountPassword.OldPasswords select new PasswordTrail() { SiteName = accountPassword.SiteName, Password = oldPassword.DecryptPassword(e), TimeStamp = oldPassword.CreatedDate }; history.AddRange(oldPasswords); } return((ActionResult) new OkObjectResult(history.OrderByDescending(x => x.TimeStamp))); }
public bool TryAuthenticate(string emailAddress, string password, out ServiceLoginToken token) { AccountPassword accountPassword = _accountPasswords.GetByEmail(emailAddress); if (accountPassword == null) { token = null; return(false); } if (accountPassword.Password != password) { token = null; return(false); } var tokenStr = _sessionIdProvider.GetSessionId(); var authenticationSession = new AuthenticationSession(accountPassword.Account, tokenStr, _nowProvider.Now); _authenticationSessionRepository.Add(authenticationSession); token = new ServiceLoginToken(tokenStr, accountPassword.Account.Id); return(true); }
public void CanAddNewAccounts() { var account1 = TestHelper.AccountMock(); var account2 = TestHelper.AccountMock(); var accountPassword1 = new AccountPassword(account1, "hello1"); var accountPassword2 = new AccountPassword(account2, "hello2"); var accountRepository = new AccountRepository(); var accountPasswordRepository = new AccountPasswordRepository(); accountRepository.Add(account1); accountRepository.Add(account2); accountPasswordRepository.Add(accountPassword1); accountPasswordRepository.Add(accountPassword2); accountRepository.GetAll(); var accountPasswords = accountPasswordRepository.GetAll(); Assert.That(account1.Id != 0); Assert.That(account2.Id != 0); Assert.That(accountPasswords.Count != 0); }
public ActionResult SignUp(string returnUrl, HeadHunter.Models.UnifiedModels.SignUpModel model) { DateTime localDate = DateTime.Now; if ((model.Account.AccountFullName == null) || (model.Account.AccountMail == null) || (model.Account.AccountType == null) || (model.Profile.ProfileUsername == null) || (model.StackOverFlowUsername == null)) { ViewBag.Msg = "Please Enter Your Mail Or Password Correctly!"; return(View()); } if ((db.Account.FirstOrDefault(m => m.AccountMail == model.Account.AccountMail)) == null) { Account newAccount = new Account(); newAccount.AccountFlag = 1; newAccount.AccountFullName = model.Account.AccountFullName; newAccount.AccountMail = model.Account.AccountMail; newAccount.AccountType = model.Account.AccountType; newAccount.AccountStatus = localDate; db.Account.Add(newAccount); db.SaveChanges(); AccountPassword newAccountPassword = new AccountPassword(); Account savedAccount = new Account(); savedAccount = db.Account.FirstOrDefault(m => m.AccountMail == model.Account.AccountMail); newAccountPassword.AccountId = savedAccount.AccountId; newAccountPassword.AccountPassword1 = model.AccountPassword.AccountPassword1; newAccountPassword.AccountPasswordFlag = true; Profil newGithubProfile = new Profil(); Profil newStackOvProfile = new Profil(); if (model.Profile.ProfileUsername != null) { newGithubProfile.AccountId = savedAccount.AccountId; newGithubProfile.ProfileFlag = true; newGithubProfile.ProfileUsername = model.Profile.ProfileUsername; newGithubProfile.SourceId = 1; db.Profil.Add(newGithubProfile); } if (model.StackOverFlowUsername != null) { newStackOvProfile.AccountId = savedAccount.AccountId; newStackOvProfile.ProfileFlag = true; newStackOvProfile.ProfileUsername = model.StackOverFlowUsername; newStackOvProfile.SourceId = 2; db.Profil.Add(newStackOvProfile); } db.AccountPassword.Add(newAccountPassword); db.SaveChanges(); } else { ViewBag.Msg = "Invalid Mail"; return(View()); } return(RedirectToLocal(returnUrl)); }
public async Task <List <string> > EditSharedAccountPwdAsync(SharedAccount sharedAccount, AccountPassword accountPassword) { if (sharedAccount == null) { throw new ArgumentNullException(nameof(sharedAccount)); } if (accountPassword == null) { throw new ArgumentNullException(nameof(accountPassword)); } _dataProtectionService.Validate(); // Update Shared Account sharedAccount.Password = _dataProtectionService.Encrypt(accountPassword.Password); sharedAccount.PasswordChangedAt = DateTime.UtcNow; // Get all accounts where used this shared account var accounts = await _accountService .Query() .Include(x => x.Employee.HardwareVaults) .Where(x => x.SharedAccountId == sharedAccount.Id && x.Deleted == false) .AsNoTracking() .ToListAsync(); List <HardwareVaultTask> tasks = new List <HardwareVaultTask>(); foreach (var account in accounts) { account.UpdatedAt = DateTime.UtcNow; account.PasswordUpdatedAt = DateTime.UtcNow; foreach (var hardwareVault in account.Employee.HardwareVaults) { tasks.Add(_hardwareVaultTaskService.GetAccountPwdUpdateTask(hardwareVault.Id, account.Id, sharedAccount.Password)); } } using (TransactionScope transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { await _sharedAccountRepository.UpdateOnlyPropAsync(sharedAccount, new string[] { nameof(SharedAccount.Password), nameof(SharedAccount.PasswordChangedAt) }); await _accountService.UpdateOnlyPropAsync(accounts, new string[] { nameof(Account.UpdatedAt), nameof(Account.PasswordUpdatedAt) }); await _hardwareVaultTaskService.AddRangeTasksAsync(tasks); transactionScope.Complete(); } return(accounts.SelectMany(x => x.Employee.HardwareVaults.Select(s => s.Id)).ToList()); }
protected override void Because() { _handler.AsDynamic().Handle(new AccountPasswordChanged(_id, "newhash", 30) { Version = 3 }); _account = _accountPasswordRepository.GetById(_id); }
public override bool ResolveErrors() { return(base.ResolveErrors() && !AccountName.NullOrEmpty() && AccountName != CONSTANTS.INVALID && !AccountPassword.NullOrEmpty() && AccountPassword != CONSTANTS.INVALID && startTime != null && AssessmentLength > 0); }
public bool ResolveErrors(string deployTarget) { return(base.ResolveErrors() && !AccountName.NullOrEmpty() && Directory.Exists(Path.Combine(deployTarget, AccountName)) && !AccountPassword.NullOrEmpty() && AccountPassword != CONSTANTS.INVALID && startTime != null && AssessmentLength > 0); }