def test_wrong_context(self):
     context1 = quickjs.Context()
     context2 = quickjs.Context()
     f = context1.eval("(function(x) { return x.a; })")
     d = context2.eval("({a: 1})")
     with self.assertRaisesRegex(ValueError, "Can not mix JS objects from different contexts."):
         f(d)
 def get_f():
     context = quickjs.Context()
     f = context.eval("""
     a = function(x) {
         return 40 + x;
     }
     """)
     return f
 def test_unicode(self):
     identity = quickjs.Function(
         "identity", """
         function identity(x) {
             return x;
         }
         """)
     context = quickjs.Context()
     for x in ["äpple", "≤≥", "☺"]:
         self.assertEqual(identity(x), x)
         self.assertEqual(context.eval('(function(){ return "' + x + '";})()'), x)
 def setUp(self):
     self.context = quickjs.Context()
     self.executor = concurrent.futures.ThreadPoolExecutor()
Example #5
0
 def __init__(self):
     self.interp = quickjs.Context()
     self.interp.eval('var foo = "bar";')
 def setUp(self):
     self.context = quickjs.Context()
Example #7
0
 def __init__(self, engine):
     self._engine = engine
     self._context = quickjs.Context()
     self.typeof = self.Function(self, self._context.eval(u'(obj => typeof obj)'))
 def __init__(self, engine):
     self._engine = engine
     self._context = quickjs.Context()
Example #9
0
 def __init__(self, engine):
     typeof = u'(function(){return function(obj){return typeof obj}})()'
     self._engine = engine
     self._context = quickjs.Context()
     self.typeof = self.Function(self, self._context.eval(typeof))
def validate(passwd) -> (str, bool):
    # print(passwd)
    # First check: Minimum length
    if len(passwd) < 8:
        return "Password is too short.", False
    # Second check: Maximum length
    if len(passwd) > 32:
        return "Password is too long.", False

    # Password analytics check
    analytics = {
        "upper": 0,
        "lower": 0,
        "num": 0,
        "symbol": 0,
        "emoji": 0
    }
    arr = list(passwd)
    for char in arr:
        if char.isupper():
            analytics["upper"] += 1
        elif char.islower():
            analytics["lower"] += 1
        elif char.isdigit():
            analytics["num"] += 1
        elif not char.isalpha():
            analytics["symbol"] += 1
        # https://stackoverflow.com/a/36217640
        if char in UNICODE_EMOJI:
            analytics["emoji"] += 1

    # Third check: Must include a letter.
    if analytics["upper"] == 0 and analytics["lower"] == 0:
        return "Password must include at least one letter.", False

    # Fourth check: Symbol count
    if analytics["symbol"] < 3:
        return "Password must include more than two special characters.", False

    # Fifth check: Must have prime amount of numbers
    if not isprime(analytics["num"]):
        return "Password must include a prime amount of numbers.", False

    # Sixth check: SpOnGeGaR cHeCk
    if analytics["upper"] != analytics["lower"]:
        return "Password must have equal amount of uppercase and lowercase characters.", False

    # Seventh check: Must include an emoji
    if analytics["emoji"] == 0:
        return "Password must include an emoji.", False

    # Eight check: Hash must start with a number
    if not list(hashlib.md5(passwd.encode()).hexdigest())[0].isdigit():
        return "Password's MD5 hash must start with a number.", False

    # Ninth check: Must be valid JavaScript (eval'd with QuickJS)
    try:
        context = quickjs.Context()
        context.set_time_limit(5)
        run = context.eval(passwd)
        if not run:
            return "Password must be valid JavaScript that evaluates to True.", True
        elif type(run) == str:
            return "Password must be valid JavaScript that doesn't return a string.", True
    except:
        return "Password must be valid JavaScript that evaluates to True.", True


    # Tenth check: Must be a palindrome.
    if (passwd != passwd[::-1]):
        return "Password must be a palindrome.", False 

    return "PASS", False
Example #11
0
import requests
from bs4 import BeautifulSoup
import re
import json
import os
import pickle
import copy
import tabulate
import quickjs

ctx = quickjs.Context()


def execJS(script):
    ctx.eval(script)
    return ctx.get('coverViewJsonData')


class PTP:
    baseURL = "https://passthepopcorn.me"
    resultsPerPage = 50

    def __init__(self, ApiUser, ApiKey, appdir, logger=None):
        if logger != None:
            self.LOG = logger
        else:
            self.LOG = None

        self._appdir = appdir
        self._getImplemented()
        self._creds = {'ApiUser': ApiUser, 'ApiKey': ApiKey}