示例#1
0
 def getRandom(self, choice):
     if self.dataConf.pattern == 'Random_normal':
         if self.dataConf.minimum is None and self.dataConf.maximum is None:
             return ''.join(random.SystemRandom().choice(choice)
                            for _ in range(10))
         elif self.dataConf.maximum is None:
             return ''.join(random.SystemRandom().choice(choice)
                            for _ in range(int(self.dataConf.minimum)))
         else:
             range_length = random.randint(int(self.dataConf.minimum),
                                           int(self.dataConf.maximum))
             return ''.join(random.SystemRandom().choice(choice)
                            for _ in range(range_length))
     elif self.dataConf.pattern == 'E_Mail':
         return '{0}@{1}.{2}'.format(rstr.domainsafe(), rstr.domainsafe(),
                                     rstr.letters(3))
     elif self.dataConf.pattern == 'Postal_Address':
         return """{0} {1} {2} {3} {4}, {5} {6} """.format(
             rstr.letters(4, 8).title(),
             rstr.letters(4, 8).title(), rstr.digits(3, 5),
             rstr.letters(4, 10).title(),
             rstr.letters(4, 15).title(), rstr.uppercase(2), rstr.digits(5))
     elif self.dataConf.pattern == 'User_Name':
         return '{0} {1}'.format(
             rstr.letters(4, 15).title(),
             rstr.letters(4, 10).title())
     elif self.dataConf.pattern == 'Url_address':
         return 'http://{0}.{1}/{2}/?{3}'.format(rstr.domainsafe(),
                                                 rstr.letters(3),
                                                 rstr.urlsafe(),
                                                 rstr.urlsafe())
     else:
         return "XXXXX"
示例#2
0
文件: routes.py 项目: chrisp87/flask
def add_lot():
	form = AddLotForm()
	form.project.query = Project.query.filter(Project.id > 0)
	
	if form.validate_on_submit():
		lotno = digits(10)
		lot = Lot.query.filter_by(lot_no=int(lotno)).first()
		if lot is None:
			lot = Lot(lot_no=lotno, created_by=current_user.id, project=form.project.data)
			db.session.add(lot)
			db.session.commit()
			return redirect(url_for('lots'))
	return render_template('add_lot.html', title='Add lot', form=form)
示例#3
0
    def test_invalid_names(self):
        # A profile with names containing non-latin characters or digits is expected to be invalid.
        zh_faker = LocaleFaker._get_faker(locale='zh')
        id_faker = LocaleFaker._get_faker(locale='id')
        tr_faker = LocaleFaker._get_faker(locale='tr')
        test_data = (
            ("latin name",
             lambda: zh_faker.name(),
             "provide this data in Latin characters"),
            ("symbols",
             lambda: rstr.punctuation(2) + rstr.punctuation(6, 10, include=rstr.lowercase(4)),
             "provide this data in Latin characters"),
            ("digits",
             lambda: rstr.lowercase(8, 12, include=set(rstr.digits())),
             "Digits are not allowed"),
            ("all caps",
             lambda: rstr.uppercase(8, 12),
             "Today is not CapsLock day"),
            ("many caps",
             lambda: rstr.uppercase(8, 12, include=rstr.lowercase(5)),
             "there are too many uppercase letters"),
            ("many caps w/prefix",
             lambda: "Mac" + rstr.uppercase(2) + rstr.lowercase(5),
             "there are too many uppercase letters"),
        )

        for field_violation, field_value, assert_content in test_data:
            for wrong_field in ('first_name', 'last_name'):
                for profile, profile_tag in (self.profile_with_no_places,
                                             self.profile_hosting,
                                             self.profile_meeting,
                                             self.profile_hosting_and_meeting,
                                             self.profile_in_book,
                                             self.profile_in_book_complex):
                    with self.subTest(condition=profile_tag, field=wrong_field, violation=field_violation):
                        data = {
                            'first_name': id_faker.first_name(),
                            'last_name': tr_faker.last_name(),
                            'birth_date': self.faker.date_between(start_date='-100y', end_date='-18y'),
                            'gender': self.faker.word(),
                        }
                        data[wrong_field] = field_value()
                        with self.subTest(value=data[wrong_field]):
                            form = self._init_form(data, instance=profile)
                            self.assertFalse(form.is_valid())
                            self.assertIn(wrong_field, form.errors)
                            self.assertTrue(
                                any(assert_content in error for error in form.errors[wrong_field]),
                                msg=repr(form.errors)
                            )
示例#4
0
    def test_invalid_names(self):
        # A family member with names containing non-latin characters or digits
        # is expected to be invalid.
        ja_faker = LocaleFaker._get_faker(locale='ja')
        test_data = (
            (
                "latin name",
                lambda: ja_faker.name(),
                "provide this data in Latin characters",
            ),
            (
                "symbols",
                lambda: rstr.punctuation(2) + rstr.punctuation(
                    6, 10, include=rstr.lowercase(4)),
                "provide this data in Latin characters",
            ),
            (
                "digits",
                lambda: rstr.lowercase(8, 12, include=set(rstr.digits())),
                "Digits are not allowed",
            ),
            (
                "all caps",
                lambda: rstr.uppercase(8, 12),
                "Today is not CapsLock day",
            ),
            (
                "many caps",
                lambda: rstr.uppercase(8, 12, include=rstr.lowercase(5)),
                "there are too many uppercase letters",
            ),
        )

        for field_violation, field_value, assert_content in test_data:
            for wrong_field in ('first_name', 'last_name'):
                with self.subTest(field=wrong_field,
                                  violation=field_violation):
                    data = {wrong_field: field_value()}
                    with self.subTest(value=data[wrong_field]):
                        form = self._init_form(data,
                                               place=self.place_with_family)
                        self.assertFalse(form.is_valid())
                        self.assertIn(wrong_field, form.errors)
                        self.assertTrue(any(
                            assert_content in error
                            for error in form.errors[wrong_field]),
                                        msg=repr(form.errors))
 def getRandom(self,choice):
     if self.dataConf.pattern == 'Random_normal':
         if self.dataConf.minimum is None and self.dataConf.maximum is None:
             return ''.join(random.SystemRandom().choice(choice) for _ in range(10))
         elif self.dataConf.maximum is None:
             return ''.join(random.SystemRandom().choice(choice) for _ in range(int(self.dataConf.minimum)))                       
         else:
             range_length=random.randint(int(self.dataConf.minimum),int(self.dataConf.maximum))
             return ''.join(random.SystemRandom().choice(choice) for _ in range(range_length))       
     elif self.dataConf.pattern == 'E_Mail':                                    
         return '{0}@{1}.{2}'.format(rstr.domainsafe(),rstr.domainsafe(),rstr.letters(3))
     elif self.dataConf.pattern == 'Postal_Address':                                    
         return """{0} {1} {2} {3} {4}, {5} {6} """.format(rstr.letters(4, 8).title(),rstr.letters(4, 8).title(),
                                                           rstr.digits(3, 5),rstr.letters(4, 10).title(),
                                                           rstr.letters(4, 15).title(),rstr.uppercase(2),rstr.digits(5))
     elif self.dataConf.pattern == 'User_Name':
         return '{0} {1}'.format(rstr.letters(4, 15).title(),rstr.letters(4, 10).title())  
     elif self.dataConf.pattern == 'Url_address':
         return 'http://{0}.{1}/{2}/?{3}'.format(rstr.domainsafe(),rstr.letters(3),rstr.urlsafe(),rstr.urlsafe())    
     else:
         return "XXXXX"
示例#6
0
 def reference():
     return rstr.digits(8)
示例#7
0
def generate_random_identifier(len):
    return rstr.digits(len)
示例#8
0
def random_code(len):
    return rstr.digits(len)
def Popula(numero_vezes, Progreso):
    cont = 0
    while cont < numero_vezes:
        conti = 0
        for dados_form_con in sumary:
            print("Campo: ", dados_form_con)
            mode = str(
                input("Escolha a letra do modo de inserção de dados" + "\n"
                      "[R]random - Campos fixos" + "\n" +
                      "[E]arquivo externo" + "\n" +
                      "[C]Passar dados Manualmente \n"))
            if (mode == "R" or mode == "r"):
                mode2 = str(
                    input(
                        " (N)nome \n (SN)Sobrenome \n (G)Genero \n (DN)DataDeNascimento \n (E)Email \n (T)Telefone \n (SO)SistemaOperacional \n"
                    ))
                if (mode2 == "N"):
                    dados_form[conti] = '{0}{1}{2}{3}{4}{5}{6}'.format(
                        rstr.uppercase(1), rstr.rstr('aeiou', 1),
                        rstr.lowercase(1), rstr.rstr('aeiou', 1),
                        rstr.lowercase(1), rstr.rstr('aeiou', 1),
                        rstr.lowercase(1))
                    conti = conti + 1
                elif (mode2 == "SN"):
                    dados_form[conti] = '{0}{1}'.format(
                        rstr.uppercase(1), rstr.lowercase(5, 16))
                    conti = conti + 1
                elif (mode2 == "G"):
                    gender = ['male', 'female']
                    dados_form[conti] = random.choice(gender)
                    conti = conti + 1
                elif (mode2 == "DN"):
                    ano_inic = [
                        "198", "197", "196", "195", "194", "193", "192", "199",
                        "200", "201"
                    ]
                    ano_random = random.choice(ano_inic) + rstr.digits(1)
                    data_rand_nasc = '{0}{1}/{2}{3}/'.format(
                        rstr.rstr('012', 1), rstr.digits(1),
                        rstr.rstr('01', 1), rstr.rstr('012', 1))
                    data_rand_nasc = data_rand_nasc + ano_random
                    dados_form[conti] = data_rand_nasc
                    conti = conti + 1
                elif (mode2 == "E"):
                    dados_form[conti] = '{0}@{1}.com.{2}'.format(
                        rstr.lowercase(exclude='@#<"^;:´`?+=[]~*{}'),
                        rstr.lowercase(5, 15), rstr.lowercase(2))
                    conti = conti + 1
                elif (mode2 == "T"):
                    dados_form[conti] = '{0}{1}'.format(
                        rstr.rstr('3,8,9', 1), rstr.digits(7))
                    conti = conti + 1
                elif (mode2 == "SO"):
                    sist = ['Debian', 'Ubuntu', 'Windows', 'Mac OS']
                    dados_form[conti] = random.choice(sist)
                    conti = conti + 1
                else:
                    print("Opção invalida")
            elif (mode == "E" or mode == "e"):
                arqex = input("Insira caminho arquivo: \n")
                try:
                    with open(arqex) as ArquivoExt:
                        dados_form[conti] = ArquivoExt.readline().rstrip('\n')
                        conti = conti + 1
                except:
                    print("Arquivo ou caminho com erro ou fora do padrão")
            elif (mode == "C" or mode == "c"):
                dados_form[conti] = input("Insira constante: ")
                conti = conti + 1
        cont = cont + 1
        payload(site, act, cont, numero_vezes)
        log(cont, dados_form)
示例#10
0
文件: Login.py 项目: mrajput7/2FA
def create_inst_table(password, hpwd):
    password = password.strip('\n')
    flag = list()
    u_mean = mean(hpwd)             # calculating mean by calling mean function
    std = standard_deviation(hpwd)  # calculating standard_deviation by calling standard_deviation function
    q = 626436561503166578967805515819693654293211766937  # binary 160 bits Prime No.- 0110110110111010011000110000110111111101001000000111110001110100100010110110000000011101110011000100001111101110000110000101001100001101100110111110000010011001
    hard_pwd = Decimal(random.random() * q)  # Generate a Random hardened password after each successful login attempt
    hard_pwd = str(hard_pwd)[0:32]         #padding
    hard_pwd = int(hard_pwd)
    shares = (tss.share_secret(m, (2 * m), hard_pwd, '', tss.Hash.SHA256))  # defining that m shares are needed from 2m shares to sucessfully create hard_pwd
    update_history(feature_val,hpwd,hard_pwd)              # calling update_history function
    file = open('InstructionTable.txt', 'w')               # opening InstructionTable file
    file.truncate()                                        # deleting previous entries from file
    length = 16 - (len(password) % 16)                     # Padding to ensure the key length is a multiple of 16 bytes (as required by AES)
    password += chr(length) * length
    for i in range(0, m):
        if (u_mean[i] + (k * std[i])) < t:                 # checking conditions to choose where the user is fast or slow for ith feature, here features are taken from zero as i start from 0.
            flag.append(0)
        elif (u_mean[i] - (k * std[i])) > t:
            flag.append(1)
        else:
            flag.append(-1)
    for i in range(0, m):                                  # encrypting m shares from password and storing according its place in instruction table,i.e left or right
        if (flag[i] == 0):
            iv = Random.new().read(AES.block_size)
            encryption_suite = AES.new(password, AES.MODE_CFB, iv)
            cipher_text0 = iv + (encryption_suite.encrypt(shares[2 * i]))  # creating correct share and storing it to left column of instruction table
            cipher = base64.b64encode(cipher_text0)
            file.write(cipher + ' ')
            iv = Random.new().read(AES.block_size)
            keyrand = str(rstr.digits(5))
            length = 16 - (len(keyrand) % 16)
            keyrand += chr(length) * length
            encryption_suite = AES.new(keyrand, AES.MODE_CFB, iv)
            cipher_text0 = iv + (encryption_suite.encrypt(shares[(2 * i) + 1]))  # creating random vague share and storing it to right column of instruction table
            cipher = base64.b64encode(cipher_text0)
            file.write(cipher + ' ')
            file.write('\n')
        if (flag[i] == 1):
            iv = Random.new().read(AES.block_size)
            keyrand = str(rstr.digits(5))
            length = 16 - (len(keyrand) % 16)
            keyrand += chr(length) * length
            encryption_suite = AES.new(keyrand, AES.MODE_CFB, iv)
            cipher_text0 = iv + (encryption_suite.encrypt(shares[2 * i]))  # creating random vague share and storing it to left column of instruction table
            cipher = base64.b64encode(cipher_text0)
            file.write(cipher + ' ')
            iv = Random.new().read(AES.block_size)
            encryption_suite = AES.new(password, AES.MODE_CFB, iv)
            cipher_text0 = iv + (encryption_suite.encrypt(shares[(2 * i) + 1]))  # creating correct share and storing it to right column of instruction table
            cipher = base64.b64encode(cipher_text0)
            file.write(cipher + ' ')
            file.write('\n')
        if (flag[i] == -1):
            iv = Random.new().read(AES.block_size)
            iv = Random.new().read(AES.block_size)
            encryption_suite = AES.new(password, AES.MODE_CFB, iv)
            cipher_text0 = iv + (encryption_suite.encrypt(shares[2 * i]))     # creating correct share and storing it to left column of instruction table
            cipher = base64.b64encode(cipher_text0)
            file.write(cipher + ' ')
            iv = Random.new().read(AES.block_size)
            encryption_suite = AES.new(password, AES.MODE_CFB, iv)
            cipher_text0 = iv + (encryption_suite.encrypt(shares[(2 * i) + 1]))  # creating correct share and storing it to right column of instruction table
            cipher = base64.b64encode(cipher_text0)
            file.write(cipher + ' ')
            file.write('\n')                                                     # closing  InstructionTable after updating file
    file.close()
示例#11
0
def create_fails_examples():
    pos_examples = []
    neg_examples = []

    # creates language W#W
    for i in range(500):
        w1 = rstr.rstr(string.digits, 1, 50)
        w2 = rstr.rstr(string.digits, len(w1))
        while w1 == w2:
            w2 = rstr.rstr(string.digits, len(w1))

        pos_examples.append(w1 + '#' + w1)
        neg_examples.append(w1 + '#' + w2)

    # till here I have 500 good examples and 500 bad examples
    with open("fail_1_pos_examples", 'w') as f:
        lines = '\n'.join(pos_examples)
        f.write(lines)
    with open("fail_1_neg_examples", 'w') as f:
        lines = '\n'.join(neg_examples)
        f.write(lines)

    # creates language w#w^r (i.e, 1234554321)
    pos_examples = []
    neg_examples = []
    for i in range(500):
        w1 = rstr.rstr(string.digits, 1, 50)
        w2 = rstr.rstr(string.digits, len(w1))
        w3 = w1[::-1]

        while w3 == w2:
            w2 = rstr.rstr(string.digits, len(w1))

        pos_examples.append(w1 + '#' + w3)
        neg_examples.append(w1 + '#' + w2)

    # till here I have 500 good examples and 500 bad examples
    with open("fail_2_pos_examples", 'w') as f:
        lines = '\n'.join(pos_examples)
        f.write(lines)
    with open("fail_2_neg_examples", 'w') as f:
        lines = '\n'.join(neg_examples)
        f.write(lines)

    # third fail lang
    pos_examples = []
    neg_examples = []
    for i in range(500):
        w1 = rstr.digits() + rstr.rstr('a') + rstr.rstr(string.digits, 100, 300) + rstr.rstr('b') + \
             rstr.rstr(string.digits, 100, 300) + rstr.rstr('c') + rstr.rstr(string.digits, 100, 300) + \
             rstr.rstr('d') + rstr.digits()

        w2 = rstr.digits() + rstr.rstr('a') + rstr.rstr(string.digits, 100, 300) + rstr.rstr('c') + \
             rstr.rstr(string.digits, 100, 300) + rstr.rstr('b') + rstr.rstr(string.digits, 100, 300) + \
             rstr.rstr('d') + rstr.digits()

        while w1 == w2:
            w2 = rstr.digits() + rstr.rstr('b') + rstr.rstr(
                string.digits, 200, 500) + rstr.rstr('a') + rstr.digits()

        pos_examples.append(w1)
        neg_examples.append(w2)

    # till here I have 500 good examples and 500 bad examples
    with open("fail_3_pos_examples", 'w') as f:
        lines = '\n'.join(pos_examples)
        f.write(lines)
    with open("fail_3_neg_examples", 'w') as f:
        lines = '\n'.join(neg_examples)
        f.write(lines)
示例#12
0
def reference_():
    return rstr.digits(9)