def random_user_id(): letters = ''.join(set(ascii_letters.lower())) alphanumeric = [letters, digits] id = str() for i in range(6): k = randint(0, 1) id += alphanumeric[k][randint(0, len(alphanumeric[k])-1)] return id
def login(email, password): data = { 'udId': _random_string(pool=ascii_letters.lower() + digits), 'deviceToken': _random_string(183, ascii_letters + digits + '-_'), 'password': md5((password + Session.SALT).encode('ascii')).hexdigest(), 'username': email, 'country': 'nl-NL', 'deviceId': 'Android Linux', 'version': '1.88', 'locale': 'nl', } resp = post('{}/account/login'.format(Session.SERVER), data=data) return Session(resp['user']['authToken'])
def user_id_gen_by_user(): letters = ''.join(set(ascii_letters.lower())) alphanumeric = [letters, digits] id_list = list() id = str() num_char = int(input('Enter the number of character\'s per ID: ')) num_id = int(input('Enter the number of ID\'s to create: ')) for j in range(num_id): for i in range(num_char): k = randint(0, 1) id += alphanumeric[k][randint(0, len(alphanumeric[k])-1)] id_list.append(id) id = "" return id_list
from string import ascii_letters alfavit = ascii_letters.lower() alfavit = sorted(list({i for i in ascii_letters.lower()})) def to_encrypt(text, delta=3): text = text.lower() shifr = "" for letter in text: if letter in alfavit: ind = alfavit.index(letter) % len(alfavit) shifr += alfavit[(ind + delta) % len(alfavit)] else: shifr += letter return shifr
def createApplicationUser(self, caller=None): userid = ''.join(random.choice(letters.lower()) for i in range( 12)) + '_' + datetime.now().strftime("%Y%m%d%H%M%S") + str(ns()) dbRole = f"""{self.event["parameters"]['tenant']}_{self.event["parameters"]['role']}""" if self.dbClient.client_type == "serverless": secret = self.dbClient.getCredentials() caller = getCallerFromSecret(secret) inviteData = { "invited_by": caller, "invite_date": str(datetime.now()), "role": dbRole, "tenant": self.event["parameters"]["tenant"] } assert match('^[a-zA-Z0-9_]+$', self.event["parameters"]["tenant"]) and match('^[a-zA-Z0-9_]+$', self.event["parameters"]["role"]), \ "Invalid tenant or role name" if self.userExists(self.event["parameters"]["email"]): raise Exception("User already exists.") if self.dbClient.client_type == "serverless": parameters = [{ 'name': 'EMAIL', 'value': { 'stringValue': f'{self.event["parameters"]["email"]}' } }, { 'name': 'FIRSTNAME', 'value': { 'stringValue': f'{self.event["parameters"]["firstname"]}' } }, { 'name': 'LASTNAME', 'value': { 'stringValue': f'{self.event["parameters"]["lastname"]}' } }, { 'name': 'DBROLE', 'value': { 'stringValue': f'{dbRole}' } }, { 'name': 'APPROLE', 'value': { 'stringValue': f'{self.event["parameters"]["role"]}' } }, { 'name': 'USERID', 'value': { 'stringValue': f'{userid}' } }, { 'name': 'TENANT', 'value': { 'stringValue': f'{self.event["parameters"]["tenant"]}' } }, { 'name': 'INVITEDATA', 'value': { 'stringValue': f'{json.dumps(inviteData)}' } }] sql = """ INSERT INTO pg_cognition.users (id, email, first_name, last_name, status, invitation_data, tenant_id) VALUES ( :USERID, :EMAIL, :FIRSTNAME, :LASTNAME, 'invited', :INVITEDATA::jsonb, (SELECT id FROM global_data.tenants WHERE name = :TENANT) ) RETURNING *, (SELECT displayname from global_data.tenants WHERE name = :TENANT) AS tenant_name; """ elif self.dbClient == "instance": parameters = { "EMAIL": self.event["parameters"]["email"], "FIRSTNAME": self.event["parameters"]["firstname"], "LASTNAME": self.event["parameters"]["lastname"], "DBROLE": self.event["parameters"]["role"], "APPROLE": self.event["parameters"]["role"], "USERID": userid, "TENANT": self.event["parameters"]["tenant"], "INVITEDATA": json.dumps(inviteData) } sql = """ INSERT INTO global_data.users (id, email, first_name, last_name, status, invitation_data, tenant_id) VALUES ( %(USERID)s, %(EMAIL)s, %(FIRSTNAME)s, %(LASTNAME)s, 'invited', %(INVITEDATA)s::jsonb, (SELECT id FROM pg_cognition.tenants WHERE name = %(TENANT)s) ) RETURNING *, (SELECT displayname from global_data.tenants WHERE name = %(TENANT)) AS tenant_name; """ try: newUser = self.dbClient.runQuery(sql, parameters)[0] return newUser except Exception as e: if self.dbClient.client_type == "serverless": parameters = { { 'name': 'USERID', 'value': { 'stringValue': f'{userid}' } }, } sql = "DELETE FROM pg_cognition.users WHERE id = :USERID;" elif self.dbClient.client_type == "instance": parameters = {"USERID": userid} sql = "DELETE FROM pg_cognition.users WHERE id = %(USERID)" try: self.dbClient.runQuery(sql, parameters) except Exception: pass raise e
from string import ascii_letters from typing import Tuple from des_ints import DESMachine crypttext = bytes.fromhex( "f45d1b8d606093949f8d09fcec9d4fa4650dd34dac6cd4c535aac237344a3edf74ef9392857285ba7198ca3a7e1bef5e338d0592417211eda0f3df2cea4d285d550b7baa0f63db6125823e3df164491b" ) blocks = [crypttext[x:8 + x] for x in range(0, len(crypttext), 8)] wordlist = [ word.lower() for word in Path('/usr/share/dict/words').read_text().splitlines() if len(word) > 1 ] allowed_letters = set(ascii_letters.lower() + " ,.'\"_-") def process(key: int) -> Tuple[bool, bytes, int]: key |= 0x0DEADBEEF0000000 machine = DESMachine(key) plain_block_0 = machine.crypt_block(blocks[0], encrypt=False) try: string = plain_block_0.decode('ascii').lower() except Exception: return (False, plain_block_0, key) if any(char not in allowed_letters for char in string): return (False, plain_block_0, key) if any(word in string for word in wordlist): return (True, plain_block_0, key) return (False, plain_block_0, key)
import psycopg2 from postgres import Postgres from psycopg2.extras import Json as postgres_jsonify from .base import DEFAULT_LOGGER, exponential_decay, timer from .exceptions import JobFailedError, JobsExhaustedError, \ UniqueInputDataConstraintError from .stats import get_stats_report if sys.version_info.major == 3: string_types = (str,) else: string_types = (basestring,) ALLOWED_CHARACTERS_IN_TABLE_NAME = set(ascii_letters.lower()) | set(digits) | set('_') JSON_POSTGRES_MIN_VER = StrictVersion('9.2') JSON_POSTGRES_OP_VER = StrictVersion('9.3') JSONB_POSTGRES_VER = StrictVersion('9.4') # According to the postgres.py documentation, we should only have a single # instantiation of the 'Postgres' class per database connection, per-process. # So we need an ugly global to store the handles - which will be instantiated # whenever the first db accessing method is called and is indexed by the # connection info. DB_HANDLES = {} ###############################################################################
''' Print lines on stdin that are English pangrams. Shortest one in PubMed 2012: "Venezuelan equine encephalomyelitis: report of an outbreak associated with jungle exposure." From PMID:6438552. Author: Pontus Stenetorp <pontus stenetorp se> Version: 2012-08-25 ''' from string import ascii_letters from sys import stdin ### Constants LOWERCASE_LETTERS = set(ascii_letters.lower()) ### def main(args): for line in (l.rstrip('\n') for l in stdin): if len(set(line.lower()) & LOWERCASE_LETTERS) == len(LOWERCASE_LETTERS): print(line) return 0 if __name__ == '__main__': from sys import argv exit(main(argv))
Shortest one in PubMed 2012: "Venezuelan equine encephalomyelitis: report of an outbreak associated with jungle exposure." From PMID:6438552. Author: Pontus Stenetorp <pontus stenetorp se> Version: 2012-08-25 ''' from string import ascii_letters from sys import stdin ### Constants LOWERCASE_LETTERS = set(ascii_letters.lower()) ### def main(args): for line in (l.rstrip('\n') for l in stdin): if len(set(line.lower()) & LOWERCASE_LETTERS) == len(LOWERCASE_LETTERS): print(line) return 0 if __name__ == '__main__': from sys import argv exit(main(argv))