public static io.Data.Return<UserSession> UserSession(string token)
        {
            UserSession usersSession = null;
            Guid tokenGUID;

            if (!Guid.TryParse(token, out tokenGUID))
                return new Return<UserSession>(io.Constants.FAILURE, Constants.CONST_NOTLOGGEDIN, "", null);

            using (var sessions = new Databases.io_auth.Views.GetSession(token))
            {
                if (sessions.QueryResult.Failed || sessions.Count == 0)
                {
                    usersSession = new UserSession(0, 0, 0, 0);
                    return new Return<UserSession>(io.Constants.FAILURE, Constants.CONST_NOTLOGGEDIN, "", null);
                }

                sessions[0].Active = true;
                sessions[0].LastActivity = DateTime.Now.ToString();

                io.Data.Return<bool> updateResult = sessions[0].UpdateRow();

                if (updateResult.Success)
                {
                    usersSession = new UserSession(sessions[0].UserSessionKey, sessions[0].EntityContactKey, sessions[0].EntityLocationKey, sessions[0].EntityKey);
                    return new io.Data.Return<UserSession>(io.Constants.SUCCESS, "", "", usersSession);
                }
                else
                {
                    usersSession = new UserSession(0, 0, 0, 0);
                    return new Return<UserSession>(io.Constants.FAILURE, Constants.CONST_SESSIONEXPIRED, "", usersSession);
                }
            }
        }
        internal static io.Data.Return<DataContracts.UpdatePasswordData> ChangePassword(UserSession userSession, DataContracts.UpdatePasswordData passwordData)
        {
            if (!passwordData.IsValid())
                return new io.Data.Return<DataContracts.UpdatePasswordData>(io.Constants.FAILURE, "Invalid Password", "", passwordData);

            if (passwordData.NewPassword.Value != passwordData.RepeatPassword.Value)
                return new io.Data.Return<DataContracts.UpdatePasswordData>(io.Constants.FAILURE, "New Password must match", "", passwordData);

            var updatePassword = iocontacts.Modules.Administration.EntityContact.SetPassword(userSession.UserSessionKey, userSession.EntityContactKey, passwordData.NewPassword.Value, passwordData.OldPassword.Value, true);

            if (updatePassword.Failed)
                return new io.Data.Return<DataContracts.UpdatePasswordData>(io.Constants.FAILURE, updatePassword.Message, "", passwordData);

            return new io.Data.Return<DataContracts.UpdatePasswordData>(io.Constants.SUCCESS, updatePassword.Message, "", passwordData);
        }
        internal static io.Data.Return<bool> PasswordExpired(UserSession userSession)
        {
            bool result = false;

            using (UserProfileExpiredPasswords rows = new UserProfileExpiredPasswords(userSession.EntityContactKey))
            {
                if (rows.QueryResult.Success && rows.Count != 0)
                    result = true;
            }

            return new io.Data.Return<bool>(io.Constants.SUCCESS, result ? "Password Expired" : "Password not Expired", "", result);
        }