Skip to content
Snippets Groups Projects
Unverified Commit a793b239 authored by David Beniamine's avatar David Beniamine
Browse files

small refactor

parent 44727a9e
No related branches found
No related tags found
No related merge requests found
...@@ -16,32 +16,20 @@ ...@@ -16,32 +16,20 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from zxcvbn import zxcvbn from getpass import getpass
from dateutil.parser import parse
import getpass
from test_pass import test_pass from test_pass import test_pass
# Read password # Read password
passwd = getpass.getpass("Merci d'entrer un mot de passe qui ne sera pas affiché\n") passwd = getpass("Merci d'entrer un mot de passe qui ne sera pas affiché\n")
word = "a"
user_inputs = [] user_inputs = []
while word != "": while True:
word = input("Veuillez entrer un mot d'aide ou une date au format jj/mm/yyyy pour le système ou tappez [entrer]" word = input("Veuillez entrer un mot d'aide ou une date au format jj/mm/yyyy pour le système ou tappez [entrer]"
" pour arrêter\n") " pour arrêter\n")
if word != "": if word == "":
try: break
date = parse(word)
words = [date.day]
words.append(date.month)
words.append(date.year)
except:
words = [word]
finally:
for word in words:
user_inputs.append(word) user_inputs.append(word)
# TODO call wrapper
lines = test_pass(passwd, user_inputs) lines = test_pass(passwd, user_inputs)
for line in lines: for line in lines:
print(line) print(line)
...@@ -28,7 +28,7 @@ html = """<!DOCTYPE html> ...@@ -28,7 +28,7 @@ html = """<!DOCTYPE html>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="author" content="David Beniamine"> <meta name="author" content="David Beniamine">
<link type="text/css" rel="stylesheet" href="css/style.css" /> <link type="text/css" rel="stylesheet" href="css/style.css" />
<title>Testeur de mot de passes</title> <title>Tetras Pass</title>
</head> </head>
<body> <body>
<div id="box"> <div id="box">
...@@ -44,7 +44,7 @@ Tetras Pass ...@@ -44,7 +44,7 @@ Tetras Pass
if form.getvalue("password") is None: if form.getvalue("password") is None:
# Password not defined => show the form # Password not defined => show the form
passwordPrompt = "Veuillez saisir le mot de passe à tester ci dessous :" passwordPrompt = "Veuillez saisir le mot de passe à tester ci dessous :"
inputsPrompt = "Veuillez saisir une liste de mots ou de dates au format jj/mm/yyyy, un indice par ligne:" inputsPrompt = "Veuillez saisir une liste d'indices : mots ou de dates au format jj/mm/yyyy, un indice par ligne:"
sendPrompt = "Lancer le test" sendPrompt = "Lancer le test"
html += """ html += """
...@@ -66,7 +66,7 @@ else: ...@@ -66,7 +66,7 @@ else:
# Split user inputs # Split user inputs
field = form.getvalue("inputs") field = form.getvalue("inputs")
if field is not None: if field is not None:
inputs = field.split('\n') inputs = field.split('\r\n')
else: else:
inputs = None inputs = None
# Retrieve results # Retrieve results
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import os import os
from dateutil.parser import parse
from itertools import combinations
from zxcvbn import zxcvbn from zxcvbn import zxcvbn
from zxcvbn.matching import add_frequency_lists from zxcvbn.matching import add_frequency_lists
...@@ -38,11 +40,29 @@ def add_dictionnaries(): ...@@ -38,11 +40,29 @@ def add_dictionnaries():
add_frequency_lists(dicts) add_frequency_lists(dicts)
# Process user inputs:
# Generate all possibile combinations of 2 parts of dates
def process_input(inputs):
dates = []
words = []
for i in inputs:
try:
date = parse(i)
dates += date.strftime("%d-%m-%y-%B-%Y-%A").split('-')
except:
words.append(i)
for n in range(2, 4):
for subset in combinations(dates, n):
words.append("".join(subset))
print(words)
return words
def test_pass(password, inputs): def test_pass(password, inputs):
# Read input # Read input
add_dictionnaries() add_dictionnaries()
results = zxcvbn(password, inputs) results = zxcvbn(password, process_input(inputs))
lines = [] lines = []
lines.append("Résultats du test\n") lines.append("Résultats du test\n")
...@@ -63,6 +83,7 @@ def test_pass(password, inputs): ...@@ -63,6 +83,7 @@ def test_pass(password, inputs):
lines.append("\n") lines.append("\n")
lines.append("Methode de hack utilisées") lines.append("Methode de hack utilisées")
# Print hack methods # Print hack methods
print(results["sequence"])
for seq in results["sequence"]: for seq in results["sequence"]:
if seq["pattern"] == "bruteforce": if seq["pattern"] == "bruteforce":
lines.append("\tMot de passe trouvé par force brute") lines.append("\tMot de passe trouvé par force brute")
...@@ -83,16 +104,13 @@ def test_pass(password, inputs): ...@@ -83,16 +104,13 @@ def test_pass(password, inputs):
lines.append("Score Global {}/4 : {}".format(results["score"], valeur[results["score"]])) lines.append("Score Global {}/4 : {}".format(results["score"], valeur[results["score"]]))
for key, values in results["feedback"].items(): for key, values in results["feedback"].items():
# Tel that we sould add the key line if there are some contents if values != [] and values != "":
needappend = True lines.append("{} :".format(tr(key)))
else:
continue
if not isinstance(values, list): if not isinstance(values, list):
# Simplify things by always using lists # Simplify things by always using lists
values = [values] values = [values]
for val in values: for val in values:
if val != "":
if needappend:
# Append key line
lines.append("{} :".format(tr(key)))
needappend = False
lines.append("\t{}".format(tr(val))) lines.append("\t{}".format(tr(val)))
return lines return lines
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment