-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.py
More file actions
50 lines (42 loc) · 1.53 KB
/
auth.py
File metadata and controls
50 lines (42 loc) · 1.53 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
import hashlib
from colorama import Fore
from config import DEFAULT_PASSWORD
import ui
import msvcrt
def get_password_with_asterisks(prompt):
print(prompt, end='', flush=True)
password = ""
while True:
char = msvcrt.getwch()
if char == '\r': # Enter tuşu
print()
break
elif char == '\x08': # Backspace
if password:
password = password[:-1]
print('\x08 \x08', end='', flush=True)
elif char != '\x00': # Özel tuşlar
password += char
print('*', end='', flush=True)
return password
def hash_password(password):
return hashlib.sha256(password.encode()).hexdigest()
STORED_PASSWORD_HASH = hash_password(DEFAULT_PASSWORD)
def authenticate():
ui.print_system("Giris yapmak icin parolayi girin.")
attempts = 0
max_attempts = 3
while attempts < max_attempts:
password = get_password_with_asterisks(Fore.YELLOW + " [PAROLA] > ")
if hash_password(password) == STORED_PASSWORD_HASH:
ui.print_success("Giris basarili. Hosgeldiniz.")
return True
else:
attempts += 1
remaining = max_attempts - attempts
if remaining > 0:
ui.print_error(f"Yanlis parola. Kalan deneme: {remaining}")
else:
ui.print_error("Maksimum deneme sayisina ulasildi. Sistem kapatiliyor.")
return False
return False