// override for custom implementation
        protected override bool ValidateUser(string userName, string password)
        {
            GenerateTimeEntryData.GenerateDataIfRequired();

            var timeEntryUser = _context.TimeEntryUsers.FirstOrDefault(u => u.UserName == userName);

            if (timeEntryUser == null)
            {
                return(false);
            }

            var security = _context.Securities.FirstOrDefault(s => s.UserId == timeEntryUser.Id);

            if (security == null)
            {
                // for this sample, we will create a security entry for the user using the supplied password
                security = new Security()
                {
                    UserId = timeEntryUser.Id,
                    Salt   = GenerateSalt()
                };

                security.Password = HashPassword(password, security.Salt);
                _context.Securities.AddObject(security);
                _context.SaveChanges();

                // In the real world, we would, of course:
                //return false;
            }

            return(DoPasswordsMatch(password, security.Salt, security.Password));
            //return base.ValidateUser(userName, password);
        }
        private void GenerateData(WeekOfYear weekOfYear)
        {
            var projects = _context.Projects.ToList();
            var users    = _context.TimeEntryUsers.ToList();
            var weekDate = TimeEntry.GetIso8601FirstDateOfWeek(weekOfYear.Year, weekOfYear.Week);

            for (int week = 0; week < 104; week++)
            {
                if (weekDate >= DateTime.Now)
                {
                    weekDate -= TimeSpan.FromDays(7);
                    // don't enter future data
                    continue;
                }

                foreach (var user in users)
                {
                    var userProjects = new List <Project>();
                    for (int i = 0; i < _random.Next(3) + 1; i++)
                    {
                        userProjects.Add(projects[_random.Next(projects.Count)]);
                    }

                    for (int day = 0; day < 5; day++)
                    {
                        var currentDate = weekDate + TimeSpan.FromDays(day);

                        var totalTime = 0.0;

                        while (totalTime < 8.0)
                        {
                            var time = Math.Round(_random.NextDouble() * 4.0, 1);
                            if (totalTime + time > 8.0)
                            {
                                time = 8.0 - totalTime;
                            }

                            totalTime += time;

                            var project   = userProjects[_random.Next(userProjects.Count)];
                            var timeEntry = new TimeEntry()
                            {
                                Date    = currentDate,
                                Hours   = time,
                                Project = project,
                                UserId  = user.Id
                            };
                            _context.TimeEntries.AddObject(timeEntry);
                        }
                    }

                    _context.SaveChanges();
                }

                weekDate -= TimeSpan.FromDays(7);
            }
        }