コード例 #1
0
        private User ValidateUser(string userName, string password)
        {
            User loggedInUser;

            try
            {
                loggedInUser = db.User.Where(u => u.UserName == userName).FirstOrDefault();

                if (loggedInUser != null)
                {
                    string decryptedPassword = SimpleEncryption.EncryptDecrypt(loggedInUser.Password, ENCYRPTION_KEY);
                    if (decryptedPassword == password)
                    {
                        return(loggedInUser);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                return(null);

                throw e;
            }
        }
コード例 #2
0
        protected override void Seed(TaskManagerContext context)
        {
            var users = new List <User> {
                new User {
                    Forename = "Aimee", Surname = "Hilliard", UserName = "******", Password = SimpleEncryption.EncryptDecrypt("Password", encryptionKey), MothersMaidenName = "test"
                },
                new User {
                    Forename = "Joe", Surname = "Smith", UserName = "******", Password = SimpleEncryption.EncryptDecrypt("Password123", encryptionKey), MothersMaidenName = "test"
                }
            };

            users.ForEach(s => context.User.Add(s));
            context.SaveChanges();

            var tasks = new List <Task> {
                new Task {
                    UserId = 1, TaskDescription = "Write unit tests", Complete = false, LastUpdated = DateTime.Parse("2018-11-01")
                },
                new Task {
                    UserId = 1, TaskDescription = "Do Code reviews", Complete = false, LastUpdated = DateTime.Parse("2018-11-01")
                },
                new Task {
                    UserId = 1, TaskDescription = "Meeting at 1", Complete = false, LastUpdated = DateTime.Parse("2018-11-01")
                },

                new Task {
                    UserId = 2, TaskDescription = "Write unit tests", Complete = false, LastUpdated = DateTime.Parse("2018-11-01")
                },
                new Task {
                    UserId = 2, TaskDescription = "Do Code reviews", Complete = false, LastUpdated = DateTime.Parse("2018-11-01")
                },
                new Task {
                    UserId = 2, TaskDescription = "Meeting at 1", Complete = false, LastUpdated = DateTime.Parse("2018-11-01")
                },
            };

            tasks.ForEach(s => context.Task.Add(s));
            context.SaveChanges();
        }