Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random # https://docs.python.org/3.6/library/random.html
- import sqlite3 # https://docs.python.org/3.6/library/sqlite3.html
- import string # https://docs.python.org/3.6/library/string.html
- def get_rand(
- str_list:str , choice:int):
- ''' This function chooses a random letter from
- a string and returns it in upper or lower
- case depending upon the choice'''
- pass
- if choice == 0:
- return random.choice(str_list)
- else:
- return random.choice(str_list).upper()
- def get_char(rule: int, posi: int):
- ''' This function returns a character depending
- on the rule and the position in the list
- The below are the characters considered
- in the password generation process
- letters = 'qwertyuiopasdfghjklzxcvbnm'
- numbers = '1234561789'
- punc = ':,β!-().?"; '''
- letters = 'qwertyuiopasdfghjklzxcvbnm'
- numbers = '1234561789'
- punc = """ ':,β!-().?";"""
- if rule >=4:
- pass
- temp = punc if posi <=4 else numbers+letters+punc
- return get_rand(temp,random.randrange(0,2))
- elif rule >=3:
- pass
- temp = letters.upper() if posi <=3 else numbers+letters
- return get_rand(temp,random.randrange(0,2))
- elif rule >=2:
- pass
- temp = numbers if posi <=2 else numbers+letters
- return get_rand(temp,0)
- else:
- pass
- return get_rand(letters,0)
- def generate_password(length: int, complexity: int) -> str:
- """Generate a random password with given length and complexity
- Complexity levels:
- Complexity == 1: return a password with only lowercase chars
- Complexity == 2: Previous level plus at least 1 digit
- Complexity == 3: Previous levels plus at least 1 uppercase char
- Complexity == 4: Previous levels plus at least 1 punctuation char
- :param length: number of characters
- :param complexity: complexity level
- :returns: generated password
- """
- pass
- pwd_list = []
- """ check if length is greater than complexity if not
- return the password with the minimum required comlexity
- length
- """
- if length < complexity:
- length = complexity
- """ generate the password"""
- temp_rule = 1
- for i in range(0,length):
- temp_val = temp_rule if temp_rule <= complexity else random.randrange(1,complexity+1)
- pwd_list.append(get_char(temp_val,i))
- temp_rule = temp_rule +1
- random.shuffle(pwd_list)
- return "".join(pwd_list)
- print(generate_password(10,4))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement