0

As I said in the title, I'm trying to use 'import re.compile()' to match an imported text file with a list of passwords. Some of them meet my criteria and some of them don't. It's just printing the whole file. My criteria is: at least 8 characters long have uppercase and lowercase letters at least one number

What's written in the txt file:

Password Attempts:
    Password2
    Positive77
    Scandalous2
    TryAgainFool99
    password
    lolipop22

I've been looking around on forums and trying some different methods but nothing seems to be working. Please help me.

with open('PasswordAttempts.txt') as file:
    content = file.read()

import re
Regx = re.compile(r'[A-Za-z\d.]{8,}')

print(Regx.findall(content))

I expect the output to be just the passwords that meet the criteria but it's printing everything on the file. Here's the output:

['Password', 'Attempts', 'Password2', 'Positive77', 'Scandalous2', 'TryAgainFool99', 'password', 'lolipop22']
Austin
  • 25,759
  • 4
  • 25
  • 48
  • You can try something like this https://stackoverflow.com/questions/41117733/validation-a-password-python instead of a regex since it might give you more control – Devesh Kumar Singh Apr 04 '19 at 03:21

1 Answers1

-1

The problem is with the regular expression itself. Check out https://regex101.com/.

This is a great resource to test your regex matching.

For example your regex did not include the number at the end, it should be [A-Za-z\d.]{8,}\d

Nhovha
  • 66
  • 5