Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. import hashlib
  2.  
  3. hash_database = {"185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969": "Pop"} #Хэшированный пароль:Логин
  4.  
  5.  
  6. def check_keys(database, key):
  7.     if key in list(database.keys()):
  8.         return True
  9.     else: return False
  10.  
  11.  
  12. def check_values(database, value):
  13.     if value in list(database.values()):
  14.         return True
  15.     else: return False
  16.  
  17.  
  18. def encrypt_string(string):
  19.     sha_signature = hashlib.sha256(string.encode()).hexdigest()
  20.     return sha_signature
  21.  
  22.  
  23. def decrypt_hash(password, user_input):
  24.     count = 0
  25.     keys = list(hash_database.keys())
  26.     values = list(hash_database.values())
  27.  
  28.     for x in range(len(hash_database)):
  29.         if values[x] == user_input and keys[x] == encrypt_string(password):
  30.             print("Вход выполнен.")
  31.             break
  32.         else:
  33.             count += 1
  34.             if count == 3:
  35.                 print("Логин и пароль не совпадают.")
  36.                 break
  37.  
  38.  
  39. def login(username):
  40.     if check_values(hash_database, username):
  41.         user_password_input = input("Введите пароль: ")
  42.         decrypt_hash(user_password_input, username)
  43.     else: print("Логина нет в базе!")
  44.  
  45.  
  46. user_hash_input = input("Введите логин: ")
  47. login(user_hash_input)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement