Пример #1
0
        /// <summary>
        /// Returns the user that has the same username and password given.
        /// throws ArgumentNull exception and Invalid Username Exception
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static User GetUserWithUsernameAndPassword(string userName, string password)
        {
            if (string.IsNullOrEmpty(userName))
            {
                throw new System.ArgumentNullException(nameof(userName));
            }

            if (string.IsNullOrEmpty(password))
            {
                throw new System.ArgumentNullException(nameof(password));
            }

            using (SportsChatQueries query = new SportsChatQueries(new SportsChatEntities()))
            {
                Guid? guid = query.GetGuidByUserName(userName);
                if (!guid.HasValue)
                {
                    throw new InvalidUserNameException("Couldn't get Guid", userName);
                }
                string hashedPassword = CreateHashedPassword(password, guid.Value);
                User u = query.GetUserByUserNameAndPasswordHash(userName, hashedPassword);
                if (u == null)
                {
                    throw new InvalidUserNameAndPasswordException("User was not found", userName);
                }
                return u;
            }
        }