public bool IsAuthorized(User user)
        {
            foreach (var role in Roles)
            {
                if (role.IsUserInRole(user))
                {
                    return (true);
                }
            }

            return (false);
        }
Exemple #2
0
        public bool IsUserInRole(User user)
        {
            if( user == null ) {
                return( false );
            }

            if( String.IsNullOrEmpty( user.Username ) ) {
                return( false );
            }

            foreach (var thisUser in Users)
            {
                if (user.Username.Equals(thisUser.Username))
                {
                    return (true);
                }

            }

            return (false);
        }
        /// <summary>
        /// Determine whether or not the credentials passed in are valid
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static bool Authenticate(string userName, string password)
        {
            if (String.IsNullOrEmpty(userName))
            {
                return (false);
            }

            if (String.IsNullOrEmpty(password))
            {
                return (false);
            }

            var user = new User(userName);

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

            if (String.IsNullOrEmpty(user.Password))
            {
                return (false);
            }

            return (user.Password.Equals(password));
        }