Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- import random
- import regex
- import numpy as np
- from pprint import pprint
- from PyInquirer import style_from_dict, Token, prompt, print_json
- from PyInquirer import Validator, ValidationError
- style = style_from_dict({
- Token.QuestionMark: '#E91E63 bold',
- Token.Selected: '#673AB7 bold',
- Token.Instruction: '', # default
- Token.Answer: '#2196f3 bold',
- Token.Question: '',
- })
- words = ["pipas", "agua", "libreta", "ventana", "alfred", "guason", "bromas", "shyamalan", "brucewillis"]
- def generate(length, diff):
- chain = ""
- if diff == "hard":
- for _ in range(length):
- chain += selectRandomChar()
- else:
- for _ in range(random.randrange(1,3)):
- chain += random.choice(words)
- for _ in range(4):
- chain += str(random.randrange(10))
- return chain
- ###### AUXILIARY FUNCTIONS ######
- def selectRandomChar():
- switcher = {
- '1': random.choice('abcdefghijklmnopqrstuvwxyz'),
- '2': random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
- '3': str(random.randrange(10)),
- '4': random.choice('{}[]()#:;^?.,!|&_~@$%/=+-*')
- }
- return switcher.get(np.random.choice(np.arange(1,5), p=[0.55, 0.25, 0.15, 0.05]).astype(str))
- def hard_question(answers):
- return answers['difficulty'] == 'hard'
- def __main__():
- print("Hi. let's set up your password.")
- questions = [
- {
- 'type': 'list',
- 'name': 'difficulty',
- 'message': 'Do you want a simple or a hard password?',
- 'choices': ['hard', 'simple']
- },
- {
- 'type': 'input',
- 'name': 'length',
- 'message': 'How long do you want your password to be? Please input the number of characters.',
- # 'validate': NumberValidator,
- 'when': hard_question,
- 'filter': lambda val: int(val)
- }]
- answers = prompt(questions, style=style)
- print('And the generated password is:')
- password = generate(answers.get('length'), answers.get('difficulty'))
- print(password)
- #print_json(answers)
- f = open('password.txt', 'w+')
- f.write(password)
- print('Your password has been saved in the file "password.txt"')
- __main__()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement