Esempio n. 1
0
        public LabDbContext.User AuthenticateUser(string userName, string password)
        {
            string hash = CalculateHash(password, userName);

            LabDbContext.User authenticated = _entities.Users.FirstOrDefault(usr => usr.UserName == userName &&
                                                                             usr.HashedPassword == hash);

            if (authenticated == null)
            {
                throw new UnauthorizedAccessException();
            }
            else
            {
                return(authenticated);
            }
        }
Esempio n. 2
0
        public LabDbContext.User CreateNewUser(Person personInstance,
                                               string userName,
                                               string password)
        {
            LabDbContext.User output = new LabDbContext.User();
            output.FullName       = "";
            output.UserName       = userName;
            output.HashedPassword = CalculateHash(password, userName);
            output.Person         = _entities.People.First(per => per.ID == personInstance.ID);

            foreach (UserRole role in _entities.UserRoles)
            {
                UserRoleMapping tempMapping = new UserRoleMapping();
                tempMapping.UserRole   = role;
                tempMapping.IsSelected = false;

                output.RoleMappings.Add(tempMapping);
            }
            _entities.Users.Add(output);
            _entities.SaveChanges();

            return(output);
        }