MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / main

Function main

DemoPrograms/Demo_Password_Login.py:22–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20
21
22def main():
23 # Use this GUI to get your password's hash code
24 def HashGeneratorGUI():
25 layout = [
26 [sg.Text('Password Hash Generator', size=(30, 1), font='Any 15')],
27 [sg.Text('Password'), sg.Input(key='-password-')],
28 [sg.Text('SHA Hash'), sg.Input('', size=(40, 1), key='hash')],
29 ]
30
31 window = sg.Window('SHA Generator', layout,
32 auto_size_text=False,
33 default_element_size=(10, 1),
34 text_justification='r',
35 return_keyboard_events=True,
36 grab_anywhere=False)
37
38 while True:
39 event, values = window.read()
40 if event == sg.WIN_CLOSED:
41 break
42
43 password = values['-password-']
44 try:
45 password_utf = password.encode('utf-8')
46 sha1hash = hashlib.sha1()
47 sha1hash.update(password_utf)
48 password_hash = sha1hash.hexdigest()
49 window['hash'].update(password_hash)
50 except:
51 pass
52 window.close()
53
54 # ----------------------------- Paste this code into your program / script -----------------------------
55 # determine if a password matches the secret password by comparing SHA1 hash codes
56 def PasswordMatches(password, a_hash):
57 password_utf = password.encode('utf-8')
58 sha1hash = hashlib.sha1()
59 sha1hash.update(password_utf)
60 password_hash = sha1hash.hexdigest()
61 return password_hash == a_hash
62
63 login_password_hash = '6adfb183a4a2c94a2f92dab5ade762a47889a5a1' # helloworld
64 password = sg.popup_get_text(
65 'Password: (type gui for other window)', password_char='*')
66 if password == 'gui': # Remove when pasting into your program
67 HashGeneratorGUI() # Remove when pasting into your program
68 return # Remove when pasting into your program
69 if password and PasswordMatches(password, login_password_hash):
70 print('Login SUCCESSFUL')
71 else:
72 print('Login FAILED!!')
73
74
75if __name__ == '__main__':

Callers 1

Calls 2

HashGeneratorGUIFunction · 0.85
PasswordMatchesFunction · 0.85

Tested by

no test coverage detected