Пример #1
0
 def test_digits_and_lower_passwords_fixed_lenght(self):
     rules = PasswordRules()
     rules.learn('abcde1')
     rules.learn('aacd12')
     generator = PasswordGenerator(rules)
     snapshots = [s for s in generator.iter_rules()]
     self.assertEqual(2, len(snapshots))
     self.assertEqual([2, 4], snapshots[0].counts)
     self.assertEqual([1, 5], snapshots[1].counts)
Пример #2
0
 def test_digits_and_lower_single_password(self):
     rules = PasswordRules()
     rules.learn('ab1')
     generator = PasswordGenerator(rules)
     self.assertEqual(1, generator.count_rules())
     snapshots = [s for s in generator.iter_rules()]
     self.assertEqual(1, len(snapshots))
     self.assertEqual([1, 2], snapshots[0].counts)
     passwords = [p for p in snapshots[0].iter_passwords()]
     expected = (permutations(10, 1) * permutations(26, 2)) * 3
     self.assertEqual(expected, len(passwords))
Пример #3
0
 def test_digits_and_lower_passwords_short(self):
     rules = PasswordRules()
     rules.learn('a1')
     rules.learn('ab1')
     generator = PasswordGenerator(rules)
     snapshots = [s for s in generator.iter_rules()]
     self.assertEqual(2, len(snapshots))
     # 1|a
     self.assertEqual([1, 1], snapshots[0].counts)
     self.assertEqual(26 * 10 * 2, snapshots[0].count_passwords())
     # 1|ab
     self.assertEqual([1, 2], snapshots[1].counts)
     self.assertEqual((26 * 25 / 2) * 10 * 3,
                      snapshots[1].count_passwords())
Пример #4
0
 def test_password_count(self):
     rules = PasswordRules()
     rules.learn('abbdABBD12')
     rules.learn('abbdABBD^2')
     generator = PasswordGenerator(rules)
     self.assertEqual(2, generator.count_rules())
     snapshots = [s for s in generator.iter_rules()]
     self.assertEqual(2, len(snapshots))
     self.assertEqual([4, 2, 4, 0], snapshots[0].counts)
     chs = (26 * 2) * (26 * 2 - 1) * (26 * 2 - 2) * (26 * 2 - 3) / (2 * 3 *
                                                                    4)
     self.assertEqual(10 * chs * chs * (10 * 9 / 2),
                      snapshots[0].count_passwords())
     self.assertEqual([4, 1, 4, 1], snapshots[1].counts)
     self.assertEqual(10 * chs * chs * 10 * 29,
                      snapshots[1].count_passwords())
Пример #5
0
 def __init__(self, filepath, password_examples):
     PasswordVerifier.__init__(self, password_examples,
                               self.is_zip_password)
     self.filepath = filepath
     fileobj = None
     with open(filepath, 'rb') as content_file:
         fileobj = io.BytesIO(content_file.read())
     self.zipFile = zipfile.ZipFile(filepath, 'r')
     rules = PasswordRules()
     for example in password_examples:
         rules.learn(example)
     self.generator = PasswordGenerator(rules)
Пример #6
0
 def __init__(self):
     self.db = Database()
     self.pwg = PasswordGenerator()
Пример #7
0
class Commands:
    def __init__(self):
        self.db = Database()
        self.pwg = PasswordGenerator()

    def save_pass_to_file(self, name, pw):
        with open("passwords.txt", "a+") as f:
            f.write((f"Name: {name} Password: {pw}" + "\n"))

    def check_export_config(self, name, pw):
        with open("config.json", "r") as f:
            data = json.load(f)

            if data[0]["export"]["database"]:
                self.db.add_password(name, pw)
                print("Password saved to database!")

            if data[0]["export"]["file"]:
                self.save_pass_to_file(name, pw)

    def new(self):
        name = input("Enter a name for the password: "******"Your new password is: {}".format(pw))

    def delete(self):
        ids = input("Enter id of password: "******"Enter a name for your password: "******"Enter your password: "******"Password stored in db!")

    def show(self):
        print("Showing passwords...")
        self.db.draw_passwords()

    def help(self):
        print(
            "List of available commmands: 'new', 'show', 'save', 'search', 'delete', 'update', 'security'"
        )

    def search(self):
        self.db.search_password()

    def update_master_password(self):
        pw = input("Enter master password: "******"[✕] '{p}' is reused {passwords.count(p)} times "))

            elif passwords.count(p) == 1:
                print(green(f"[✓]'{p}' is not reused"))

        with open("common_passwords.txt", "r") as f:
            data = f.read()
            for p in set(passwords):
                if p in data:
                    print(red(p + " is a common password!"))
Пример #8
0
def index():
    pass_gen = PasswordGenerator()
    password = pass_gen.generate()[0]
    return render_template('index.html', password=password)
Пример #9
0
# https://repl.it/@Levashov/hack
from generator import PasswordGenerator

generator1 = PasswordGenerator(use_specsymbols=True)
print(generator1.generate_password())
print(generator1.generate_password())

generator2 = PasswordGenerator(length=10)
print(generator2.generate_password())
print(generator2.generate_password())

generator3 = PasswordGenerator(use_letters=False, use_digits=False)
print(generator3.generate_password())
print(generator3.generate_password())
Пример #10
0
def main_(argv):

    if ui_data['progress_cb'] is not None:
        ui_data['progress_cb']('', 0)

    if '-h' in argv or '--help' in argv:
        print_usage()
        sys.exit(0)

    opts = {
        'length': 20,
        'save': False,
        'local': [],
        'remote': False,
        'mangle': True,
        'mangle-case': True,
        'mangle-chars': True,
        'mangle-punc': True,
        'num': 1,
        'to_mangle': False,
        'fresh': False,
        'verbose': 0
    }
    i = 1

    while i < len(argv):
        a = argv[i]

        if a == '--save' or a == '-s':
            opts['save'] = True

        elif a == '--dont-mangle':
            opts['mangle'] = False
        elif a == '--dont-mangle-case':
            opts['mangle-case'] = False
        elif a == '--dont-mangle-chars':
            opts['mangle-chars'] = False
        elif a == '--dont-mangle-punc':
            opts['mangle-punc'] = False
        elif a == '-n' or a == '--number':
            opts['num'] = int(argv[i + 1])
            i += 1
        elif a == '-r' or a == '--remote-train':
            opts['remote'] = int(argv[i + 1])
            i += 1
        elif a == '-l' or a == '--local-train':

            while i < len(argv) - 1:
                if argv[i + 1].startswith('-'):
                    break
                if argv[i + 1] == '@':
                    i += 1
                    break
                opts['local'] += [argv[i + 1]]
                i += 1

        elif a == '-m' or a == '--mangle':
            opts['to_mangle'] = argv[i + 1]

        elif a == '-f' or a == '--fresh':
            opts['fresh'] = True

        elif a == '-v':
            opts['verbose'] += 1

        else:
            opts['length'] = int(a)
        i += 1

    opts['length'] = int(opts['length'])

    m = None
    trainer = MarkovTrainer()
    if opts['fresh']:
        verbose('Fresh load -- no previous data restored', opts['verbose'])
    else:
        m = trainer.load_state()

    if m is None:
        m = Markov()

    if opts['remote']:
        verbose('Training remotely', opts['verbose'])
        for x in xrange(int(opts['remote'])):
            if ui_data['progress_cb'] is not None:
                ui_data['progress_cb']('Training remotely',
                                       (x + 1.0) / float(opts['remote']))
            m = trainer.train_remotely(m, 1)

    if opts['local']:
        for i, path in enumerate(opts['local']):
            verbose('Training locally: {0}'.format(path), opts['verbose'])
            if ui_data['progress_cb'] is not None:
                ui_data['progress_cb']('Training locally',
                                       (i + 1.0) / len(opts['local']))
            m = trainer.train_locally(m, path)

    if opts['save']:
        trainer.save_state(m)

    for x in xrange(int(opts['num'])):
        pg = PasswordGenerator(m)
        pg.mangle_punc = opts['mangle-punc']
        pg.mangle_case = opts['mangle-case']
        pg.mangle_chars = opts['mangle-chars']

        if ui_data['progress_cb'] is not None:
            ui_data['progress_cb']('Generating passwords',
                                   (x + 1.0) / int(opts['num']))

        phrase = opts['to_mangle'] if opts[
            'to_mangle'] is not False else pg.generate_base_phrase(
                opts['length'])

        if opts['mangle']:
            phrase = pg.mangle(phrase)
        yield phrase
    if ui_data['progress_cb'] is not None:
        ui_data['progress_cb']('Done', 1)
Пример #11
0
def main_(argv):
  
  if ui_data['progress_cb'] is not None:
    ui_data['progress_cb']('', 0)
    
  if '-h' in argv or '--help' in argv:
    print_usage()
    sys.exit(0)
    
  opts = {
      'length': 20,
      'save': False,
      'local':[],
      'remote':False,
      'mangle' : True,
      'mangle-case' : True,
      'mangle-chars': True,
      'mangle-punc': True,
      'num': 1,
      'to_mangle':False,
      'fresh': False,
      'verbose':0

    }
  i = 1
  
  while i < len(argv):
    a = argv[i]
    
    if a == '--save' or a == '-s':
      opts['save'] = True

    elif a == '--dont-mangle':
      opts['mangle'] = False
    elif a == '--dont-mangle-case':
      opts['mangle-case'] = False
    elif a == '--dont-mangle-chars':
      opts['mangle-chars'] = False
    elif a == '--dont-mangle-punc':
      opts['mangle-punc'] = False
    elif a == '-n' or a == '--number':
      opts['num'] = int(argv[i+1])
      i+=1
    elif a == '-r' or a == '--remote-train':
      opts['remote'] = int(argv[i+1])
      i+=1
    elif a == '-l' or a == '--local-train':
      
      while i < len(argv)-1:        
        if argv[i+1].startswith('-'):
          break
        if argv[i+1] == '@':
          i+=1 
          break
        opts['local'] += [argv[i+1]]
        i+=1
      
    elif a == '-m' or a == '--mangle':
      opts['to_mangle'] = argv[i+1]
      
    elif a == '-f' or a == '--fresh':
      opts['fresh'] = True
      
    elif a == '-v':
      opts['verbose']+=1
      
    else:
      opts['length'] = int(a)
    i+=1
  
  opts['length'] = int(opts['length'])

  m = None
  trainer = MarkovTrainer()
  if opts['fresh']:
    verbose('Fresh load -- no previous data restored', opts['verbose'])
  else:
    m = trainer.load_state()
    
  if m is None:  
    m = Markov()
    

  if opts['remote']:
    verbose('Training remotely', opts['verbose'])
    for x in xrange(int(opts['remote'])):
      if ui_data['progress_cb'] is not None:
        ui_data['progress_cb']('Training remotely', (x+1.0)/float(opts['remote']))
      m = trainer.train_remotely(m, 1)
  
    
  if opts['local']:
    for i, path in enumerate(opts['local']):
      verbose('Training locally: {0}'.format(path), opts['verbose'])
      if ui_data['progress_cb'] is not None:
        ui_data['progress_cb']('Training locally', (i+1.0)/len(opts['local']))
      m = trainer.train_locally(m, path)
      
      
  if opts['save']:
    trainer.save_state(m)
  
  for x in xrange(int(opts['num'])):
    pg = PasswordGenerator(m)  
    pg.mangle_punc = opts['mangle-punc']
    pg.mangle_case = opts['mangle-case']
    pg.mangle_chars = opts['mangle-chars']
    
    if ui_data['progress_cb'] is not None:
      ui_data['progress_cb']('Generating passwords', (x+1.0)/int(opts['num']))

    
    phrase = opts['to_mangle'] if opts['to_mangle'] is not False else pg.generate_base_phrase(opts['length'])
    
    if opts['mangle']:
      phrase = pg.mangle(phrase)
    yield phrase
  if ui_data['progress_cb'] is not None:
    ui_data['progress_cb']('Done', 1)
Пример #12
0
 def test_empty(self):
     rules = PasswordRules()
     generator = PasswordGenerator(rules)
     snapshots = [s for s in generator.iter_rules()]
     self.assertEqual(0, len(snapshots))
     self.assertEqual(0, generator.count_rules())