-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_forgot.py
More file actions
151 lines (125 loc) · 6.45 KB
/
Copy pathpassword_forgot.py
File metadata and controls
151 lines (125 loc) · 6.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from mongo_connection import defined_id_user, change_password_user, is_strong_password
from mongo_connection import data_mongo, check_hashed
class BoxPasswordForgot(BoxLayout):
def build(self):
self.title = "Password Forgot"
self.orientation = "vertical"
self.black_space()
self.label_title()
self.username_label()
self.input_username_know()
self.black_space()
self.button_search_question()
self.black_space()
self.label_question()
self.response_label()
self.input_answer()
self.black_space()
self.button_check_answer()
self.black_space()
self.change_password_button()
self.black_space()
# ----------------------------------------------------------- Title -----------------------------------------------------------#
def label_title(self):
self.title = Label(text="Password forget?", size_hint=(.2, .1), pos_hint={'x': 0.4},
color=[0.59, 0.239, 0.89, 1], font_size=40)
self.add_widget(self.title)
# ----------------------------------------------------------- Username -----------------------------------------------------------#
def username_label(self):
self.message_username = Label(text="Insert your username", size_hint=(.2, .2), pos_hint={'x': 0.4})
self.add_widget(self.message_username)
def input_username_know(self):
self.username = TextInput(text="",
size_hint=(0.24, .07), pos_hint={'x': 0.38, 'y': 0.1}, halign="center")
self.add_widget(self.username)
def button_search_question(self):
self.button_load_question = Button(text="Search user", size_hint=(.24, .05),
pos_hint={'x': 0.38}, color=[1, 1, 1, 1],
background_color=[0.59, 0.239, 0.89, 1])
self.button_load_question.bind(on_press=self.search_and_load)
self.add_widget(self.button_load_question)
# ----------------------------------------------------------- central text -----------------------------------------------------------#
def label_question(self):
self.secret_question = Label(text='This is your secret question', size_hint=(0.24, 0.05),
pos_hint={'x': 0.38, 'y': 0.1}, color=[0.59, 0.239, 0.89, 1], font_size=20)
self.add_widget(self.secret_question)
# ----------------------------------------------------------- secret response -----------------------------------------------------------#
def response_label(self):
self.message_response = Label(text="Enter your answer", size_hint=(.2, .2), pos_hint={'x': 0.4})
self.add_widget(self.message_response)
def input_answer(self):
self.input_answer = TextInput(text="", size_hint=(0.24, 0.07), pos_hint={'x': 0.38, 'y': 0.1}, halign="center")
self.add_widget(self.input_answer)
def button_check_answer(self):
self.button_check = Button(text="check my answer", size_hint=(.24, .06),
pos_hint={'x': 0.38}, color=[1, 1, 1, 1], background_color=[0.59, 0.239, 0.89, 1])
self.button_check.bind(on_press=self.check_user_informations)
self.add_widget(self.button_check)
# ----------------------------------------------------------- Change Password -----------------------------------------------------------#
def change_password_button(self):
self.button_new_password = Button(text="change my password", size_hint=(.24, .06),
pos_hint={'x': 0.38}, color=[1, 1, 1, 1],
background_color=[0.59, 0.239, 0.89, 1])
self.button_new_password.bind(on_press=self.change_password_user)
self.add_widget(self.button_new_password)
# ----------------------------------------------------------- Space Graphic -----------------------------------------------------------#
def black_space(self):
self.black = Label(size_hint=(.4, .1))
self.add_widget(self.black)
# ----------------------------------------------------------- Function -----------------------------------------------------------#
def search_and_load(self, instance):
"""
return the mystery question of the user
:param instance: /
:return: Nothin
"""
username = self.username.text
dic_user = data_mongo()
if username in dic_user:
question = dic_user[username][4]
self.secret_question.text = "Your secret question is : " + question
def check_user_informations(self, instance):
"""
check if the secret answer by the user is the same than in the database
:param instance: /
:return: /
"""
dic_user = data_mongo()
username_give = self.username.text
answer_give = self.input_answer.text.upper()
answed_crypted = bytes(answer_give, encoding="utf-8")
if username_give not in dic_user:
self.secret_question.text = "User not found"
else:
if check_hashed(answed_crypted, dic_user[username_give][5]):
self.message_response.text = "Correct! Enter your new password"
self.input_answer.text = ""
else:
self.message_response.text = "Incorrect answer"
def change_password_user(self, instance):
"""
change the password of the user into the database
:param instance: /
:return: /
"""
username = self.username.text
password = self.input_answer.text
if is_strong_password(password):
change_password_user(username, password)
self.secret_question.text = ""
self.message_response.text = ""
self.title.text = "Password changed!"
else:
self.secret_question.text = "The password need to have minimum 8 caracteres, a digit and a letter"
class PasswordForgot(App):
def build(self):
Layout = BoxPasswordForgot()
Layout.build()
return Layout
if __name__ == '__main__':
PasswordForgot().run()