Skip to content

Commit 98e4e34

Browse files
committed
add password strength checker tutorial
1 parent dc0a94c commit 98e4e34

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
6868
- [How to Exploit Command Injection Vulnerabilities in Python](https://thepythoncode.com/article/how-to-exploit-command-injection-vulnerabilities-in-python). ([code](ethical-hacking/exploit-command-injection))
6969
- [How to Make Malware Persistent in Python](https://thepythoncode.com/article/how-to-create-malware-persistent-in-python). ([code](ethical-hacking/persistent-malware))
7070
- [How to Remove Persistent Malware in Python](https://thepythoncode.com/article/removingg-persistent-malware-in-python). ([code](ethical-hacking/remove-persistent-malware))
71+
- [How to Check Password Strength with Python](https://thepythoncode.com/article/test-password-strength-with-python). ([code](ethical-hacking/checking-password-strength))
7172

7273
- ### [Machine Learning](https://www.thepythoncode.com/topic/machine-learning)
7374
- ### [Natural Language Processing](https://www.thepythoncode.com/topic/nlp)

Diff for: ethical-hacking/checking-password-strength/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Check Password Strength with Python](https://thepythoncode.com/article/test-password-strength-with-python)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from zxcvbn import zxcvbn
2+
import pprint, getpass, sys
3+
4+
5+
def test_single_password():
6+
password = getpass.getpass("[?] Enter your password: ")
7+
result = zxcvbn(password)
8+
print(f"Value: {result['password']}")
9+
print(f"Password Score: {result['score']}/4")
10+
print(f"Crack Time: {result['crack_times_display']['offline_slow_hashing_1e4_per_second']}")
11+
print(f"Feedback: {result['feedback']['suggestions']}")
12+
#pprint.pp(result)
13+
14+
15+
def test_multiple_passwords(password_file):
16+
try:
17+
with open(password_file, 'r') as passwords:
18+
for password in passwords:
19+
result = zxcvbn(password.strip('\n'))
20+
print('\n[+] ######################')# for readability
21+
print(f"Value: {result['password']}")
22+
print(f"Password Score: {result['score']}/4")
23+
print(f"Crack Time: {result['crack_times_display']['offline_slow_hashing_1e4_per_second']}")
24+
print(f"Feedback: {result['feedback']['suggestions']}")
25+
#pprint.pp(result)
26+
27+
except Exception:
28+
print('[!] Please make sure to specify an accessible file containing passwords.')
29+
30+
31+
if len(sys.argv) == 2:
32+
test_multiple_passwords(sys.argv[1])
33+
elif len(sys.argv) == 1:
34+
test_single_password()
35+
else:
36+
print('Usage: python test_password_strength.py <file> (for a file containing passwords) or \
37+
\npython test_password_strength.py (for a single password.)')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
password
2+
1234567
3+
abc123cba159
4+
Sioplabxtre_9lTGCE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zxcvbn

0 commit comments

Comments
 (0)