/// <inheritdoc /> public async Task <AuthenticatedUser> AuthenticateAsync(string userName, string password) { var userDb = this.context.Users.SingleOrDefault(x => x.UserName == userName); if (userDb == null) { userDb = new User { Id = SecurityEngine.GenerateId(), UserName = userName, Password = SecurityEngine.HashPassword(password), CreationDate = DateTime.UtcNow, LastLoginDate = DateTime.UtcNow, }; this.context.Users.Add(userDb); await this.context.SaveChangesAsync(); return(this.mapper.Map <AuthenticatedUser>(userDb)); } if (SecurityEngine.VerifyPassword(password, userDb.Password)) { userDb.LastLoginDate = DateTime.UtcNow; await this.context.SaveChangesAsync(); return(this.mapper.Map <AuthenticatedUser>(userDb)); } return(null); }
public void GenerateId(int iterations) { var guids = new List <Guid>(); for (var i = 0; i < iterations; i++) { guids.Add(SecurityEngine.GenerateId()); } Assert.True(guids.Distinct().Count() == guids.Count); }
/// <inheritdoc /> public void Add(Guid userId, string projectName) { var project = new Model.Project(); project.Id = SecurityEngine.GenerateId(); project.UserId = userId; project.Name = projectName; this.SetCreated(project, userId); this.context.Projects.Add(project); this.context.SaveChanges(); }